23 #define LOCKFILE "/var/lock/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];
92 char *args[] = { "sendcommand", NULL, NULL, NULL } ;
94 fprintf(stderr, "Attaching to server...\n");
95 sprintf(portname, "%d", config.c_port_number);
97 attach_to_server(3, args, hostbuf, portbuf);
99 fprintf(stderr, "%s\n",&buf[4]);
100 sprintf(buf,"IPGM %d", config.c_ipgm_secret);
103 fprintf(stderr, "%s\n",&buf[4]);
114 int main(int argc, char **argv)
120 strcpy(bbs_home_directory, BBSDIR);
124 * Change directories if specified
126 for (a=1; a<argc; ++a) {
127 if (!strncmp(argv[a], "-h", 2)) {
128 strcpy(bbs_home_directory, argv[a]);
129 strcpy(bbs_home_directory, &bbs_home_directory[2]);
133 if (strlen(cmd)>0) strcat(cmd, " ");
134 strcat(cmd, argv[a]);
140 signal(SIGINT,cleanup);
141 signal(SIGQUIT,cleanup);
142 signal(SIGHUP,cleanup);
143 signal(SIGTERM,cleanup);
145 fprintf(stderr, "sendcommand: started. pid=%ld\n",(long)getpid());
147 np_attach_to_server();
150 fprintf(stderr, "%s\n", cmd);
153 fprintf(stderr, "%s\n", buf);
156 while (serv_gets(buf), strcmp(buf, "000")) {
160 else if (buf[0]=='4') {
162 if (fgets(buf, 255, stdin)==NULL) strcpy(buf, "000");
163 if (strcmp(buf, "000")) serv_puts(buf);
164 } while (strcmp(buf, "000"));
167 fprintf(stderr, "sendcommand: processing ended.\n");