Debian Codegraph @

COSMIC/EXE/spmchk.c

raw
1 /* spmchk: see if there is a portmaster running on the specified machine
2 * by attempting to open a Socket on it. If the attempt fails, return 1,
3 * otherwise 0.
4 *
5 * XTDIO_USAGE: spmchk [machine]
6 *
7 * This can be used in a script like so:
8 *
9 * spmchk || Spm
10 *
11 * -or-
12 *
13 * spmchk || (nohup Spm > /dev/null)&
14 *
15 * to avoid having Spm print out an error message if it is already
16 * running.
17 *
18 * Author: Marty Olevitch, Dec 1993
19 * (This routine is placed into the public domain.)
20 */
21
22 #include <stdio.h>
23 #include <string.h>
24 #include "sockets.h"
25
26 /* ---------------------------------------------------------------------
27 * Definitions:
28 */
29 #define BUFSIZE 256
30
31 /* ---------------------------------------------------------------------
32 * Prototypes:
33 */
34 #ifdef __PROTOTYPE__
35 int main(int, char **);
36 #else
37 extern main();
38 #endif
39
40 /* ---------------------------------------------------------------------
41 * Source Code:
42 */
43
44 #ifdef __PROTOTYPE__
45 int main(
46 int argc,
47 char **argv)
48 #else
49 int main(argc, argv)
50 int argc;
51 char **argv;
52 #endif
53 {
54 char hostnm[BUFSIZE];
55 Socket *s;
56
57 Sinit();
58
59 if(argc > 1) strcpy(hostnm, argv[1]);
60 else gethostname(hostnm,BUFSIZE);
61
62 s = Sopen_clientport(hostnm, "PMClient", PORTMASTER);
63 if (!s) {
64 exit(2);
65 }
66 Sclose(s);
67
68 #ifdef vms
69 exit(1);
70 #else
71 exit(0);
72 #endif
73 }
74
75 /* --------------------------------------------------------------------- */