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,"%d\n",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) {
91 char *args[] = { "sendcommand", "localhost", NULL, NULL } ;
93 fprintf(stderr, "Attaching to server...\n");
94 sprintf(portname, "%d", config.c_port_number);
96 attach_to_server(3, args);
98 fprintf(stderr, "%s\n",&buf[4]);
99 sprintf(buf,"IPGM %d", config.c_ipgm_secret);
102 fprintf(stderr, "%s\n",&buf[4]);
113 int main(int argc, char **argv)
119 strcpy(bbs_home_directory, BBSDIR);
123 * Change directories if specified
125 for (a=1; a<argc; ++a) {
126 if (!strncmp(argv[a], "-h", 2)) {
127 strcpy(bbs_home_directory, argv[a]);
128 strcpy(bbs_home_directory, &bbs_home_directory[2]);
132 strcat(cmd, argv[a]);
138 signal(SIGINT,cleanup);
139 signal(SIGQUIT,cleanup);
140 signal(SIGHUP,cleanup);
141 signal(SIGTERM,cleanup);
143 fprintf(stderr, "sendcommand: started. pid=%d\n",getpid());
145 np_attach_to_server();
148 fprintf(stderr, "%s\n", cmd);
151 fprintf(stderr, "%s\n", buf);
153 fprintf(stderr, "sendcommand: processing ended.\n");