23 #define LOCKFILE "/tmp/LCK.sendcommand"
26 extern int home_specified;
30 * make sure only one copy of sendcommand runs at a time, using lock files
32 int set_lockfile(void) {
36 if ((lfp = fopen(LOCKFILE,"r")) != NULL) {
37 fscanf(lfp,"%d",&onppid);
39 if (!kill(onppid, 0) || errno == EPERM) return 1;
42 lfp=fopen(LOCKFILE,"w");
43 fprintf(lfp,"%ld\n",(long)getpid());
48 void remove_lockfile(void) {
53 * Why both cleanup() and nq_cleanup() ? Notice the alarm() call in
54 * cleanup() . If for some reason sendcommand hangs waiting for the server
55 * to clean up, the alarm clock goes off and the program exits anyway.
56 * The cleanup() routine makes a check to ensure it's not reentering, in
57 * case the ipc module looped it somehow.
59 void nq_cleanup(int e)
67 static int nested = 0;
70 signal(SIGALRM,nq_cleanup);
71 if (nested++ < 1) serv_puts("QUIT");
76 * This is implemented as a function rather than as a macro because the
77 * client-side IPC modules expect logoff() to be defined. They call logoff()
78 * when a problem connecting or staying connected to the server occurs.
86 * Connect sendcommand to the Citadel server running on this computer.
88 void np_attach_to_server(void) {
89 char hostbuf[256], portbuf[256];
91 char *args[] = { "sendcommand", NULL } ;
93 fprintf(stderr, "Attaching to server...\n");
94 attach_to_server(1, args, hostbuf, portbuf);
96 fprintf(stderr, "%s\n",&buf[4]);
97 sprintf(buf,"IPGM %d", config.c_ipgm_secret);
100 fprintf(stderr, "%s\n",&buf[4]);
111 int main(int argc, char **argv)
117 strcpy(bbs_home_directory, BBSDIR);
121 * Change directories if specified
123 for (a=1; a<argc; ++a) {
124 if (!strncmp(argv[a], "-h", 2)) {
125 strcpy(bbs_home_directory, argv[a]);
126 strcpy(bbs_home_directory, &bbs_home_directory[2]);
130 if (strlen(cmd)>0) strcat(cmd, " ");
131 strcat(cmd, argv[a]);
137 signal(SIGINT,cleanup);
138 signal(SIGQUIT,cleanup);
139 signal(SIGHUP,cleanup);
140 signal(SIGTERM,cleanup);
142 fprintf(stderr, "sendcommand: started. pid=%ld\n",(long)getpid());
144 np_attach_to_server();
147 fprintf(stderr, "%s\n", cmd);
150 fprintf(stderr, "%s\n", buf);
153 while (serv_gets(buf), strcmp(buf, "000")) {
157 else if (buf[0]=='4') {
159 if (fgets(buf, 255, stdin)==NULL) strcpy(buf, "000");
160 if (strcmp(buf, "000")) serv_puts(buf);
161 } while (strcmp(buf, "000"));
164 fprintf(stderr, "sendcommand: processing ended.\n");