hlfsd.c (41145) | hlfsd.c (42633) |
---|---|
1/* 2 * Copyright (c) 1997-1998 Erez Zadok 3 * Copyright (c) 1989 Jan-Simon Pendry 4 * Copyright (c) 1989 Imperial College of Science, Technology & Medicine 5 * Copyright (c) 1989 The Regents of the University of California. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * Jan-Simon Pendry at Imperial College, London. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. All advertising materials mentioning features or use of this software | 1/* 2 * Copyright (c) 1997-1998 Erez Zadok 3 * Copyright (c) 1989 Jan-Simon Pendry 4 * Copyright (c) 1989 Imperial College of Science, Technology & Medicine 5 * Copyright (c) 1989 The Regents of the University of California. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * Jan-Simon Pendry at Imperial College, London. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. All advertising materials mentioning features or use of this software |
20 * must display the following acknowledgement: | 20 * must display the following acknowledgment: |
21 * This product includes software developed by the University of 22 * California, Berkeley and its contributors. 23 * 4. Neither the name of the University nor the names of its contributors 24 * may be used to endorse or promote products derived from this software 25 * without specific prior written permission. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE --- 4 unchanged lines hidden (view full) --- 33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * SUCH DAMAGE. 38 * 39 * %W% (Berkeley) %G% 40 * | 21 * This product includes software developed by the University of 22 * California, Berkeley and its contributors. 23 * 4. Neither the name of the University nor the names of its contributors 24 * may be used to endorse or promote products derived from this software 25 * without specific prior written permission. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE --- 4 unchanged lines hidden (view full) --- 33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37 * SUCH DAMAGE. 38 * 39 * %W% (Berkeley) %G% 40 * |
41 * $Id: hlfsd.c,v 1.2 1998/08/23 22:52:08 obrien Exp $ | 41 * $Id: hlfsd.c,v 1.3 1998/11/14 03:13:31 obrien Exp $ |
42 * 43 * HLFSD was written at Columbia University Computer Science Department, by 44 * Erez Zadok <ezk@cs.columbia.edu> and Alexander Dupuy <dupuy@cs.columbia.edu> 45 * It is being distributed under the same terms and conditions as amd does. 46 */ 47 48#ifdef HAVE_CONFIG_H 49# include <config.h> --- 28 unchanged lines hidden (view full) --- 78/* 79 * GLOBALS: 80 */ 81SVCXPRT *nfsxprt; 82char *alt_spooldir = ALT_SPOOLDIR; 83char *home_subdir = HOME_SUBDIR; 84char *logfile = DEFAULT_LOGFILE; 85char *passwdfile = NULL; /* alternate passwd file to use */ | 42 * 43 * HLFSD was written at Columbia University Computer Science Department, by 44 * Erez Zadok <ezk@cs.columbia.edu> and Alexander Dupuy <dupuy@cs.columbia.edu> 45 * It is being distributed under the same terms and conditions as amd does. 46 */ 47 48#ifdef HAVE_CONFIG_H 49# include <config.h> --- 28 unchanged lines hidden (view full) --- 78/* 79 * GLOBALS: 80 */ 81SVCXPRT *nfsxprt; 82char *alt_spooldir = ALT_SPOOLDIR; 83char *home_subdir = HOME_SUBDIR; 84char *logfile = DEFAULT_LOGFILE; 85char *passwdfile = NULL; /* alternate passwd file to use */ |
86#if 0 |
|
86char *progname; | 87char *progname; |
88int foreground = 1; /* This is the top-level server */ 89#endif |
|
87char *slinkname = 0; 88char hostname[MAXHOSTNAMELEN + 1] = "localhost"; 89int cache_interval = DEFAULT_CACHE_INTERVAL; | 90char *slinkname = 0; 91char hostname[MAXHOSTNAMELEN + 1] = "localhost"; 92int cache_interval = DEFAULT_CACHE_INTERVAL; |
90int foreground = 1; /* This is the top-level server */ | |
91gid_t hlfs_gid = (gid_t) INVALIDID; 92int masterpid = 0; 93int noverify = 0; | 93gid_t hlfs_gid = (gid_t) INVALIDID; 94int masterpid = 0; 95int noverify = 0; |
94int orig_umask; | 96int orig_umask = 022; |
95int serverpid = 0; 96nfstime startup; | 97int serverpid = 0; 98nfstime startup; |
99#if 0 |
|
97pid_t mypid; /* Current process id */ | 100pid_t mypid; /* Current process id */ |
101#endif |
|
98serv_state amd_state; 99u_short nfs_port; 100 101/* symbol must be available always */ 102#ifdef MOUNT_TABLE_ON_FILE 103char *mnttab_file_name = MNTTAB_FILE_NAME; 104#else /* not MOUNT_TABLE_ON_FILE */ 105char *mnttab_file_name = NULL; 106#endif /* not MOUNT_TABLE_ON_FILE */ 107 | 102serv_state amd_state; 103u_short nfs_port; 104 105/* symbol must be available always */ 106#ifdef MOUNT_TABLE_ON_FILE 107char *mnttab_file_name = MNTTAB_FILE_NAME; 108#else /* not MOUNT_TABLE_ON_FILE */ 109char *mnttab_file_name = NULL; 110#endif /* not MOUNT_TABLE_ON_FILE */ 111 |
112#if 0 |
|
108#ifdef DEBUG 109int debug_flags = 0; 110#endif /* DEBUG */ | 113#ifdef DEBUG 114int debug_flags = 0; 115#endif /* DEBUG */ |
116#endif |
|
111 112/* forward declarations */ 113void hlfsd_going_down(int rc); 114 115 116static void 117usage(void) 118{ 119 fprintf(stderr, 120 "Usage: %s [-Cfhnpv] [-a altdir] [-c cache-interval] [-g group]\n", | 117 118/* forward declarations */ 119void hlfsd_going_down(int rc); 120 121 122static void 123usage(void) 124{ 125 fprintf(stderr, 126 "Usage: %s [-Cfhnpv] [-a altdir] [-c cache-interval] [-g group]\n", |
121 progname); | 127 am_get_progname()); |
122 fprintf(stderr, "\t[-i interval] [-l logfile] [-o mntopts] [-P passwdfile]\n"); 123 show_opts('x', xlog_opt); 124#ifdef DEBUG 125 show_opts('D', dbg_opt); 126#endif /* DEBUG */ 127 fprintf(stderr, "\t[dir_name [subdir]]\n"); 128 exit(2); 129} 130 131 132int 133main(int argc, char *argv[]) 134{ 135 char *dot; 136 char *mntopts = (char *) NULL; 137 char hostpid_fs[MAXHOSTNAMELEN + 1 + 16]; /* room for ":(pid###)" */ 138 char progpid_fs[PROGNAMESZ + 1 + 11]; /* room for ":pid" */ 139 char preopts[128]; | 128 fprintf(stderr, "\t[-i interval] [-l logfile] [-o mntopts] [-P passwdfile]\n"); 129 show_opts('x', xlog_opt); 130#ifdef DEBUG 131 show_opts('D', dbg_opt); 132#endif /* DEBUG */ 133 fprintf(stderr, "\t[dir_name [subdir]]\n"); 134 exit(2); 135} 136 137 138int 139main(int argc, char *argv[]) 140{ 141 char *dot; 142 char *mntopts = (char *) NULL; 143 char hostpid_fs[MAXHOSTNAMELEN + 1 + 16]; /* room for ":(pid###)" */ 144 char progpid_fs[PROGNAMESZ + 1 + 11]; /* room for ":pid" */ 145 char preopts[128]; |
146 char *progname; |
|
140 int forcecache = 0; 141 int forcefast = 0; 142 int genflags = 0; 143 int opt, ret; 144 int opterrs = 0; 145 int retry; 146 int soNFS; /* NFS socket */ 147 int s = -99; --- 18 unchanged lines hidden (view full) --- 166 /* get program name and truncate so we don't overflow progpid_fs */ 167 168 if ((progname = strrchr(argv[0], '/')) != NULL) 169 progname++; 170 else 171 progname = argv[0]; 172 if ((int) strlen(progname) > PROGNAMESZ) /* truncate to reasonable size */ 173 progname[PROGNAMESZ] = '\0'; | 147 int forcecache = 0; 148 int forcefast = 0; 149 int genflags = 0; 150 int opt, ret; 151 int opterrs = 0; 152 int retry; 153 int soNFS; /* NFS socket */ 154 int s = -99; --- 18 unchanged lines hidden (view full) --- 173 /* get program name and truncate so we don't overflow progpid_fs */ 174 175 if ((progname = strrchr(argv[0], '/')) != NULL) 176 progname++; 177 else 178 progname = argv[0]; 179 if ((int) strlen(progname) > PROGNAMESZ) /* truncate to reasonable size */ 180 progname[PROGNAMESZ] = '\0'; |
181 am_set_progname(progname); |
|
174 | 182 |
175 while ((opt = getopt(argc, argv, "a:c:CD:fg:hi:l:no:pP:x:v")) != EOF) | 183 while ((opt = getopt(argc, argv, "a:c:CD:fg:hi:l:no:pP:x:v")) != -1) |
176 switch (opt) { 177 178 case 'a': 179 if (!optarg || optarg[0] != '/') { 180 printf("%s: invalid directory for -a: %s\n", | 184 switch (opt) { 185 186 case 'a': 187 if (!optarg || optarg[0] != '/') { 188 printf("%s: invalid directory for -a: %s\n", |
181 progname, optarg); | 189 am_get_progname(), optarg); |
182 exit(3); 183 } 184 alt_spooldir = optarg; 185 break; 186 187 case 'c': 188 if (!atoi(optarg)) { 189 printf("%s: invalid interval for -c: %s\n", | 190 exit(3); 191 } 192 alt_spooldir = optarg; 193 break; 194 195 case 'c': 196 if (!atoi(optarg)) { 197 printf("%s: invalid interval for -c: %s\n", |
190 progname, optarg); | 198 am_get_progname(), optarg); |
191 exit(3); 192 } 193 cache_interval = atoi(optarg); 194 break; 195 196 case 'C': 197 forcecache++; 198 break; --- 4 unchanged lines hidden (view full) --- 203 204 case 'g': 205 hlfs_group = optarg; 206 break; 207 208 case 'i': 209 if (!atoi(optarg)) { 210 printf("%s: invalid interval for -i: %s\n", | 199 exit(3); 200 } 201 cache_interval = atoi(optarg); 202 break; 203 204 case 'C': 205 forcecache++; 206 break; --- 4 unchanged lines hidden (view full) --- 211 212 case 'g': 213 hlfs_group = optarg; 214 break; 215 216 case 'i': 217 if (!atoi(optarg)) { 218 printf("%s: invalid interval for -i: %s\n", |
211 progname, optarg); | 219 am_get_progname(), optarg); |
212 exit(3); 213 } 214 reloadinterval.it_interval.tv_sec = atoi(optarg); 215 reloadinterval.it_value.tv_sec = atoi(optarg); 216 break; 217 218 case 'l': 219 logfile = optarg; --- 22 unchanged lines hidden (view full) --- 242 case 'x': 243 opterrs += switch_option(optarg); 244 break; 245 246 case 'D': 247#ifdef DEBUG 248 opterrs += debug_option(optarg); 249#else /* not DEBUG */ | 220 exit(3); 221 } 222 reloadinterval.it_interval.tv_sec = atoi(optarg); 223 reloadinterval.it_value.tv_sec = atoi(optarg); 224 break; 225 226 case 'l': 227 logfile = optarg; --- 22 unchanged lines hidden (view full) --- 250 case 'x': 251 opterrs += switch_option(optarg); 252 break; 253 254 case 'D': 255#ifdef DEBUG 256 opterrs += debug_option(optarg); 257#else /* not DEBUG */ |
250 fprintf(stderr, "%s: not compiled with DEBUG -- sorry.\n", progname); | 258 fprintf(stderr, "%s: not compiled with DEBUG -- sorry.\n", am_get_progname()); |
251#endif /* not DEBUG */ 252 break; 253 254 case 'h': 255 case '?': 256 opterrs++; 257 } 258 259 /* set some default debugging options */ 260 if (xlog_level_init == ~0) 261 switch_option(""); 262 /* need my pid before any dlog/plog */ | 259#endif /* not DEBUG */ 260 break; 261 262 case 'h': 263 case '?': 264 opterrs++; 265 } 266 267 /* set some default debugging options */ 268 if (xlog_level_init == ~0) 269 switch_option(""); 270 /* need my pid before any dlog/plog */ |
263 mypid = getpid(); | 271 am_set_mypid(); |
264#ifdef DEBUG 265 switch_option("debug"); 266#endif /* DEBUG */ 267 268/* 269 * Terminate if did not ask to forcecache (-C) and hlfsd would not be able 270 * to set the minimum cache intervals. 271 */ 272#if !defined(MNT2_NFS_OPT_ACREGMIN) && !defined(MNT2_NFS_OPT_NOAC) && !defined(HAVE_FIELD_NFS_ARGS_T_ACREGMIN) 273 if (!forcecache) { | 272#ifdef DEBUG 273 switch_option("debug"); 274#endif /* DEBUG */ 275 276/* 277 * Terminate if did not ask to forcecache (-C) and hlfsd would not be able 278 * to set the minimum cache intervals. 279 */ 280#if !defined(MNT2_NFS_OPT_ACREGMIN) && !defined(MNT2_NFS_OPT_NOAC) && !defined(HAVE_FIELD_NFS_ARGS_T_ACREGMIN) 281 if (!forcecache) { |
274 fprintf(stderr, "%s: will not be able to turn off attribute caches.\n", progname); | 282 fprintf(stderr, "%s: will not be able to turn off attribute caches.\n", am_get_progname()); |
275 exit(1); 276 } 277#endif /* !defined(MNT2_NFS_OPT_ACREGMIN) && !defined(MNT2_NFS_OPT_NOAC) && !defined(HAVE_FIELD_NFS_ARGS_T_ACREGMIN) */ 278 279 280 switch (argc - optind) { 281 case 2: 282 home_subdir = argv[optind + 1]; --- 14 unchanged lines hidden (view full) --- 297 exit(1); 298 } 299 setbuf(stdout, (char *) NULL); 300 umask(0); 301 302 /* find gid for hlfs_group */ 303 if ((grp = getgrnam(hlfs_group)) == (struct group *) NULL) { 304 fprintf(stderr, "%s: cannot get gid for group \"%s\".\n", | 283 exit(1); 284 } 285#endif /* !defined(MNT2_NFS_OPT_ACREGMIN) && !defined(MNT2_NFS_OPT_NOAC) && !defined(HAVE_FIELD_NFS_ARGS_T_ACREGMIN) */ 286 287 288 switch (argc - optind) { 289 case 2: 290 home_subdir = argv[optind + 1]; --- 14 unchanged lines hidden (view full) --- 305 exit(1); 306 } 307 setbuf(stdout, (char *) NULL); 308 umask(0); 309 310 /* find gid for hlfs_group */ 311 if ((grp = getgrnam(hlfs_group)) == (struct group *) NULL) { 312 fprintf(stderr, "%s: cannot get gid for group \"%s\".\n", |
305 progname, hlfs_group); | 313 am_get_progname(), hlfs_group); |
306 } else { 307 hlfs_gid = grp->gr_gid; 308 } 309 310 /* get hostname for logging and open log before we reset umask */ 311 gethostname(hostname, sizeof(hostname)); 312 hostname[sizeof(hostname) - 1] = '\0'; 313 if ((dot = strchr(hostname, '.')) != NULL) 314 *dot = '\0'; | 314 } else { 315 hlfs_gid = grp->gr_gid; 316 } 317 318 /* get hostname for logging and open log before we reset umask */ 319 gethostname(hostname, sizeof(hostname)); 320 hostname[sizeof(hostname) - 1] = '\0'; 321 if ((dot = strchr(hostname, '.')) != NULL) 322 *dot = '\0'; |
315 if (logfile) 316 switch_to_logfile(logfile); | |
317 orig_umask = umask(0); | 323 orig_umask = umask(0); |
324 if (logfile) 325 switch_to_logfile(logfile, orig_umask); |
|
318 319#if defined(DEBUG) && !defined(MOUNT_TABLE_ON_FILE) 320 if (debug_flags & D_MTAB) 321 dlog("-D mtab option ignored"); 322#endif /* defined(DEBUG) && !defined(MOUNT_TABLE_ON_FILE) */ 323 324 /* avoid hanging on other NFS servers if started elsewhere */ 325 if (chdir("/") < 0) --- 8 unchanged lines hidden (view full) --- 334 */ 335 336 if (dir_name[0] != '/' 337 || ((slinkname = strrchr(dir_name, '/')), *slinkname++ = '\0', 338 (dir_name[0] == '\0' || slinkname[0] == '\0'))) { 339 if (slinkname) 340 *--slinkname = '/'; 341 printf("%s: invalid mount directory/link %s\n", | 326 327#if defined(DEBUG) && !defined(MOUNT_TABLE_ON_FILE) 328 if (debug_flags & D_MTAB) 329 dlog("-D mtab option ignored"); 330#endif /* defined(DEBUG) && !defined(MOUNT_TABLE_ON_FILE) */ 331 332 /* avoid hanging on other NFS servers if started elsewhere */ 333 if (chdir("/") < 0) --- 8 unchanged lines hidden (view full) --- 342 */ 343 344 if (dir_name[0] != '/' 345 || ((slinkname = strrchr(dir_name, '/')), *slinkname++ = '\0', 346 (dir_name[0] == '\0' || slinkname[0] == '\0'))) { 347 if (slinkname) 348 *--slinkname = '/'; 349 printf("%s: invalid mount directory/link %s\n", |
342 progname, dir_name); | 350 am_get_progname(), dir_name); |
343 exit(3); 344 } 345 346 clock_valid = 0; /* invalidate logging clock */ 347 348 if (!forcefast) { 349 /* make sure mount point exists and is at least mode 555 */ 350 if (stat(dir_name, &stmodes) < 0) 351 if (errno != ENOENT || mkdirs(dir_name, 0555) < 0 352 || stat(dir_name, &stmodes) < 0) 353 fatalerror(dir_name); 354 355 if ((stmodes.st_mode & 0555) != 0555) { 356 fprintf(stderr, "%s: directory %s not read/executable\n", | 351 exit(3); 352 } 353 354 clock_valid = 0; /* invalidate logging clock */ 355 356 if (!forcefast) { 357 /* make sure mount point exists and is at least mode 555 */ 358 if (stat(dir_name, &stmodes) < 0) 359 if (errno != ENOENT || mkdirs(dir_name, 0555) < 0 360 || stat(dir_name, &stmodes) < 0) 361 fatalerror(dir_name); 362 363 if ((stmodes.st_mode & 0555) != 0555) { 364 fprintf(stderr, "%s: directory %s not read/executable\n", |
357 progname, dir_name); | 365 am_get_progname(), dir_name); |
358 plog(XLOG_WARNING, "directory %s not read/executable", 359 dir_name); 360 } 361 362 /* warn if extraneous stuff will be hidden by mount */ 363 if ((mountdir = opendir(dir_name)) == NULL) 364 fatalerror(dir_name); 365 366 while ((direntry = readdir(mountdir)) != NULL) { 367 if (!NSTREQ(".", direntry->d_name, NAMLEN(direntry)) && 368 !NSTREQ("..", direntry->d_name, NAMLEN(direntry)) && 369 !NSTREQ(slinkname, direntry->d_name, NAMLEN(direntry))) 370 break; 371 } 372 373 if (direntry != NULL) { 374 fprintf(stderr, "%s: %s/%s will be hidden by mount\n", | 366 plog(XLOG_WARNING, "directory %s not read/executable", 367 dir_name); 368 } 369 370 /* warn if extraneous stuff will be hidden by mount */ 371 if ((mountdir = opendir(dir_name)) == NULL) 372 fatalerror(dir_name); 373 374 while ((direntry = readdir(mountdir)) != NULL) { 375 if (!NSTREQ(".", direntry->d_name, NAMLEN(direntry)) && 376 !NSTREQ("..", direntry->d_name, NAMLEN(direntry)) && 377 !NSTREQ(slinkname, direntry->d_name, NAMLEN(direntry))) 378 break; 379 } 380 381 if (direntry != NULL) { 382 fprintf(stderr, "%s: %s/%s will be hidden by mount\n", |
375 progname, dir_name, direntry->d_name); | 383 am_get_progname(), dir_name, direntry->d_name); |
376 plog(XLOG_WARNING, "%s/%s will be hidden by mount\n", 377 dir_name, direntry->d_name); 378 } 379 closedir(mountdir); 380 381 /* make sure alternate spool dir exists */ 382 if ((errno = mkdirs(alt_spooldir, OPEN_SPOOLMODE))) { 383 fprintf(stderr, "%s: cannot create alternate dir ", | 384 plog(XLOG_WARNING, "%s/%s will be hidden by mount\n", 385 dir_name, direntry->d_name); 386 } 387 closedir(mountdir); 388 389 /* make sure alternate spool dir exists */ 390 if ((errno = mkdirs(alt_spooldir, OPEN_SPOOLMODE))) { 391 fprintf(stderr, "%s: cannot create alternate dir ", |
384 progname); | 392 am_get_progname()); |
385 perror(alt_spooldir); 386 plog(XLOG_ERROR, "cannot create alternate dir %s: %m", 387 alt_spooldir); 388 } 389 chmod(alt_spooldir, OPEN_SPOOLMODE); 390 391 /* create failsafe link to alternate spool directory */ 392 slinkname[-1] = '/'; /* unsplit dir_name to include link */ 393 if (lstat(dir_name, &stmodes) == 0 && 394 (stmodes.st_mode & S_IFMT) != S_IFLNK) { 395 fprintf(stderr, "%s: failsafe %s not a symlink\n", | 393 perror(alt_spooldir); 394 plog(XLOG_ERROR, "cannot create alternate dir %s: %m", 395 alt_spooldir); 396 } 397 chmod(alt_spooldir, OPEN_SPOOLMODE); 398 399 /* create failsafe link to alternate spool directory */ 400 slinkname[-1] = '/'; /* unsplit dir_name to include link */ 401 if (lstat(dir_name, &stmodes) == 0 && 402 (stmodes.st_mode & S_IFMT) != S_IFLNK) { 403 fprintf(stderr, "%s: failsafe %s not a symlink\n", |
396 progname, dir_name); | 404 am_get_progname(), dir_name); |
397 plog(XLOG_WARNING, "failsafe %s not a symlink\n", 398 dir_name); 399 } else { 400 unlink(dir_name); 401 402 if (symlink(alt_spooldir, dir_name) < 0) { 403 fprintf(stderr, 404 "%s: cannot create failsafe symlink %s -> ", | 405 plog(XLOG_WARNING, "failsafe %s not a symlink\n", 406 dir_name); 407 } else { 408 unlink(dir_name); 409 410 if (symlink(alt_spooldir, dir_name) < 0) { 411 fprintf(stderr, 412 "%s: cannot create failsafe symlink %s -> ", |
405 progname, dir_name); | 413 am_get_progname(), dir_name); |
406 perror(alt_spooldir); 407 plog(XLOG_WARNING, 408 "cannot create failsafe symlink %s -> %s: %m", 409 dir_name, alt_spooldir); 410 } 411 } 412 413 slinkname[-1] = '\0'; /* resplit dir_name */ --- 98 unchanged lines hidden (view full) --- 512 localsocket.sin_family = AF_INET; 513 localsocket.sin_port = htons(nfsxprt->xp_port); 514#endif /* not HAVE_TRANSPORT_TYPE_TLI */ 515 516 /* 517 * Update hostname field. 518 * Make some name prog:pid (i.e., hlfsd:174) for hostname 519 */ | 414 perror(alt_spooldir); 415 plog(XLOG_WARNING, 416 "cannot create failsafe symlink %s -> %s: %m", 417 dir_name, alt_spooldir); 418 } 419 } 420 421 slinkname[-1] = '\0'; /* resplit dir_name */ --- 98 unchanged lines hidden (view full) --- 520 localsocket.sin_family = AF_INET; 521 localsocket.sin_port = htons(nfsxprt->xp_port); 522#endif /* not HAVE_TRANSPORT_TYPE_TLI */ 523 524 /* 525 * Update hostname field. 526 * Make some name prog:pid (i.e., hlfsd:174) for hostname 527 */ |
520 sprintf(progpid_fs, "%s:%d", progname, masterpid); | 528 sprintf(progpid_fs, "%s:%d", am_get_progname(), masterpid); |
521 522 /* Most kernels have a name length restriction. */ 523 if ((int) strlen(progpid_fs) >= (int) MAXHOSTNAMELEN) 524 strcpy(progpid_fs + MAXHOSTNAMELEN - 3, ".."); 525 526 genflags = compute_mount_flags(&mnt); 527 528 retry = hasmntval(&mnt, MNTTAB_OPT_RETRY); --- 59 unchanged lines hidden (view full) --- 588 * -Erez Zadok. 589 */ 590 if (debug_flags & D_DAEMON) { /* asked for -D daemon */ 591 plog(XLOG_INFO, "parent NFS mounting hlfsd service points"); 592 if (mount_fs(&mnt, genflags, (caddr_t) &nfs_args, retry, type, 0, NULL, mnttab_file_name) < 0) 593 fatal("nfsmount: %m"); 594 } else { /* asked for -D nodaemon */ 595 if (fork() == 0) { /* child runs mount */ | 529 530 /* Most kernels have a name length restriction. */ 531 if ((int) strlen(progpid_fs) >= (int) MAXHOSTNAMELEN) 532 strcpy(progpid_fs + MAXHOSTNAMELEN - 3, ".."); 533 534 genflags = compute_mount_flags(&mnt); 535 536 retry = hasmntval(&mnt, MNTTAB_OPT_RETRY); --- 59 unchanged lines hidden (view full) --- 596 * -Erez Zadok. 597 */ 598 if (debug_flags & D_DAEMON) { /* asked for -D daemon */ 599 plog(XLOG_INFO, "parent NFS mounting hlfsd service points"); 600 if (mount_fs(&mnt, genflags, (caddr_t) &nfs_args, retry, type, 0, NULL, mnttab_file_name) < 0) 601 fatal("nfsmount: %m"); 602 } else { /* asked for -D nodaemon */ 603 if (fork() == 0) { /* child runs mount */ |
596 mypid = getpid(); | 604 am_set_mypid(); |
597 foreground = 0; 598 plog(XLOG_INFO, "child NFS mounting hlfsd service points"); 599 if (mount_fs(&mnt, genflags, (caddr_t) &nfs_args, retry, type, 0, NULL, mnttab_file_name) < 0) { 600 fatal("nfsmount: %m"); 601 } 602 exit(0); /* all went well */ 603 } else { /* fork failed or parent running */ 604 plog(XLOG_INFO, "parent waiting 1sec for mount..."); --- 60 unchanged lines hidden (view full) --- 665#endif /* DEBUG */ 666 child = fork(); 667 668 if (child < 0) 669 fatal("fork: %m"); 670 671 if (child != 0) { /* parent process - save child pid */ 672 masterpid = child; | 605 foreground = 0; 606 plog(XLOG_INFO, "child NFS mounting hlfsd service points"); 607 if (mount_fs(&mnt, genflags, (caddr_t) &nfs_args, retry, type, 0, NULL, mnttab_file_name) < 0) { 608 fatal("nfsmount: %m"); 609 } 610 exit(0); /* all went well */ 611 } else { /* fork failed or parent running */ 612 plog(XLOG_INFO, "parent waiting 1sec for mount..."); --- 60 unchanged lines hidden (view full) --- 673#endif /* DEBUG */ 674 child = fork(); 675 676 if (child < 0) 677 fatal("fork: %m"); 678 679 if (child != 0) { /* parent process - save child pid */ 680 masterpid = child; |
673 mypid = getpid(); /* for logging routines */ | 681 am_set_mypid(); /* for logging routines */ |
674 return; 675 } 676 677 /* 678 * CHILD CODE: 679 * initialize server 680 */ 681 682 plog(XLOG_INFO, "initializing home directory database"); 683 plt_init(); /* initialize database */ 684 plog(XLOG_INFO, "home directory database initialized"); 685 | 682 return; 683 } 684 685 /* 686 * CHILD CODE: 687 * initialize server 688 */ 689 690 plog(XLOG_INFO, "initializing home directory database"); 691 plt_init(); /* initialize database */ 692 plog(XLOG_INFO, "home directory database initialized"); 693 |
686 masterpid = serverpid = mypid = getpid(); /* for logging routines */ | 694 masterpid = serverpid = am_set_mypid(); /* for logging routines */ |
687 688 /* 689 * SIGALRM/SIGHUP: reload password database if timer expired 690 * or user sent HUP signal. 691 */ 692#ifdef HAVE_SIGACTION 693 sa.sa_handler = reload; 694 sa.sa_flags = 0; --- 16 unchanged lines hidden (view full) --- 711 sigemptyset(&(sa.sa_mask)); 712 sigaddset(&(sa.sa_mask), SIGTERM); 713 sigaction(SIGTERM, &sa, NULL); 714#else /* not HAVE_SIGACTION */ 715 signal(SIGTERM, cleanup); 716#endif /* not HAVE_SIGACTION */ 717 718 /* | 695 696 /* 697 * SIGALRM/SIGHUP: reload password database if timer expired 698 * or user sent HUP signal. 699 */ 700#ifdef HAVE_SIGACTION 701 sa.sa_handler = reload; 702 sa.sa_flags = 0; --- 16 unchanged lines hidden (view full) --- 719 sigemptyset(&(sa.sa_mask)); 720 sigaddset(&(sa.sa_mask), SIGTERM); 721 sigaction(SIGTERM, &sa, NULL); 722#else /* not HAVE_SIGACTION */ 723 signal(SIGTERM, cleanup); 724#endif /* not HAVE_SIGACTION */ 725 726 /* |
719 * SIGCHLD: interlock sycronization and testing | 727 * SIGCHLD: interlock synchronization and testing |
720 */ 721#ifdef HAVE_SIGACTION 722 sa.sa_handler = interlock; 723 sa.sa_flags = 0; 724 sigemptyset(&(sa.sa_mask)); 725 sigaddset(&(sa.sa_mask), SIGCHLD); 726 sigaction(SIGCHLD, &sa, NULL); 727#else /* not HAVE_SIGACTION */ --- 74 unchanged lines hidden (view full) --- 802 if (getpid() != masterpid) 803 return; 804 805 /* 806 * If received a SIGHUP, close and reopen the log file (so that it 807 * can be rotated) 808 */ 809 if (signum == SIGHUP && logfile) | 728 */ 729#ifdef HAVE_SIGACTION 730 sa.sa_handler = interlock; 731 sa.sa_flags = 0; 732 sigemptyset(&(sa.sa_mask)); 733 sigaddset(&(sa.sa_mask), SIGCHLD); 734 sigaction(SIGCHLD, &sa, NULL); 735#else /* not HAVE_SIGACTION */ --- 74 unchanged lines hidden (view full) --- 810 if (getpid() != masterpid) 811 return; 812 813 /* 814 * If received a SIGHUP, close and reopen the log file (so that it 815 * can be rotated) 816 */ 817 if (signum == SIGHUP && logfile) |
810 switch_to_logfile(logfile); | 818 switch_to_logfile(logfile, orig_umask); |
811 812 /* 813 * parent performs the reload, while the child continues to serve 814 * clients accessing the home dir link. 815 */ 816 if ((child = fork()) > 0) { 817 serverpid = child; /* parent runs here */ | 819 820 /* 821 * parent performs the reload, while the child continues to serve 822 * clients accessing the home dir link. 823 */ 824 if ((child = fork()) > 0) { 825 serverpid = child; /* parent runs here */ |
818 mypid = getpid(); | 826 am_set_mypid(); |
819 820 plt_init(); 821 822 if (kill(child, SIGKILL) < 0) { 823 plog(XLOG_ERROR, "kill child: %m"); 824 } else { /* wait for child to die before continue */ 825 if (wait(&status) != child) { 826 /* --- 7 unchanged lines hidden (view full) --- 834 } 835 } 836 serverpid = masterpid; 837 } else if (child < 0) { 838 plog(XLOG_ERROR, "unable to fork: %m"); 839 } else { 840 /* let child handle requests while we reload */ 841 serverpid = getpid(); | 827 828 plt_init(); 829 830 if (kill(child, SIGKILL) < 0) { 831 plog(XLOG_ERROR, "kill child: %m"); 832 } else { /* wait for child to die before continue */ 833 if (wait(&status) != child) { 834 /* --- 7 unchanged lines hidden (view full) --- 842 } 843 } 844 serverpid = masterpid; 845 } else if (child < 0) { 846 plog(XLOG_ERROR, "unable to fork: %m"); 847 } else { 848 /* let child handle requests while we reload */ 849 serverpid = getpid(); |
842 mypid = getpid(); | 850 am_set_mypid(); |
843 } 844} 845 846 847RETSIGTYPE 848cleanup(int signum) 849{ 850 struct stat stbuf; --- 7 unchanged lines hidden (view full) --- 858 if (getpid() != masterpid) 859 return; 860 861#ifdef DEBUG 862 amuDebug(D_DAEMON) 863#endif /* DEBUG */ 864 if (fork() != 0) { 865 masterpid = 0; | 851 } 852} 853 854 855RETSIGTYPE 856cleanup(int signum) 857{ 858 struct stat stbuf; --- 7 unchanged lines hidden (view full) --- 866 if (getpid() != masterpid) 867 return; 868 869#ifdef DEBUG 870 amuDebug(D_DAEMON) 871#endif /* DEBUG */ 872 if (fork() != 0) { 873 masterpid = 0; |
866 mypid = getpid(); | 874 am_set_mypid(); |
867 return; 868 } | 875 return; 876 } |
869 mypid = getpid(); | 877 am_set_mypid(); |
870 871 for (;;) { 872 while ((umount_result = UMOUNT_FS(dir_name, mnttab_file_name)) == EBUSY) { 873#ifdef DEBUG 874 dlog("cleanup(): umount delaying for 10 seconds"); 875#endif /* DEBUG */ 876 sleep(10); 877 } 878 if (stat(dir_name, &stbuf) == 0 && stbuf.st_ino == ROOTID) { 879 plog(XLOG_ERROR, "unable to unmount %s", dir_name); 880 plog(XLOG_ERROR, "suspending, unmount before terminating"); | 878 879 for (;;) { 880 while ((umount_result = UMOUNT_FS(dir_name, mnttab_file_name)) == EBUSY) { 881#ifdef DEBUG 882 dlog("cleanup(): umount delaying for 10 seconds"); 883#endif /* DEBUG */ 884 sleep(10); 885 } 886 if (stat(dir_name, &stbuf) == 0 && stbuf.st_ino == ROOTID) { 887 plog(XLOG_ERROR, "unable to unmount %s", dir_name); 888 plog(XLOG_ERROR, "suspending, unmount before terminating"); |
881 kill(mypid, SIGSTOP); | 889 kill(am_mypid, SIGSTOP); |
882 continue; /* retry unmount */ 883 } 884 break; 885 } 886 887#ifdef DEBUG 888 dlog("cleanup(): killing processes and terminating"); 889 amuDebug(D_DAEMON) --- 19 unchanged lines hidden (view full) --- 909 exit(4); 910 } 911} 912 913 914void 915hlfsd_going_down(int rc) 916{ | 890 continue; /* retry unmount */ 891 } 892 break; 893 } 894 895#ifdef DEBUG 896 dlog("cleanup(): killing processes and terminating"); 897 amuDebug(D_DAEMON) --- 19 unchanged lines hidden (view full) --- 917 exit(4); 918 } 919} 920 921 922void 923hlfsd_going_down(int rc) 924{ |
917 int mypid = getpid(); | 925 int mypid = getpid(); /* XXX: should this be the global am_mypid */ |
918 919 if (mypid == masterpid) 920 cleanup(0); 921 else if (mypid == serverpid) 922 kill(masterpid, SIGTERM); 923 924 exit(rc); 925} --- 4 unchanged lines hidden (view full) --- 930{ 931 if (logfile && !STREQ(logfile, "stderr")) { 932 char lessmess[128]; 933 int messlen; 934 935 messlen = strlen(mess); 936 937 if (!STREQ(&mess[messlen + 1 - sizeof(ERRM)], ERRM)) | 926 927 if (mypid == masterpid) 928 cleanup(0); 929 else if (mypid == serverpid) 930 kill(masterpid, SIGTERM); 931 932 exit(rc); 933} --- 4 unchanged lines hidden (view full) --- 938{ 939 if (logfile && !STREQ(logfile, "stderr")) { 940 char lessmess[128]; 941 int messlen; 942 943 messlen = strlen(mess); 944 945 if (!STREQ(&mess[messlen + 1 - sizeof(ERRM)], ERRM)) |
938 fprintf(stderr, "%s: %s\n", progname, mess); | 946 fprintf(stderr, "%s: %s\n", am_get_progname(), mess); |
939 else { 940 strcpy(lessmess, mess); 941 lessmess[messlen - 4] = '\0'; 942 943 if (errno < sys_nerr) | 947 else { 948 strcpy(lessmess, mess); 949 lessmess[messlen - 4] = '\0'; 950 951 if (errno < sys_nerr) |
944 fprintf(stderr, "%s: %s: %s\n", progname, | 952 fprintf(stderr, "%s: %s: %s\n", am_get_progname(), |
945 lessmess, sys_errlist[errno]); 946 else 947 fprintf(stderr, "%s: %s: Error %d\n", | 953 lessmess, sys_errlist[errno]); 954 else 955 fprintf(stderr, "%s: %s: Error %d\n", |
948 progname, lessmess, errno); | 956 am_get_progname(), lessmess, errno); |
949 } 950 } 951 plog(XLOG_FATAL, mess); 952 953 hlfsd_going_down(1); 954} | 957 } 958 } 959 plog(XLOG_FATAL, mess); 960 961 hlfsd_going_down(1); 962} |