struct node *mknode(char *type, char *code, char *wire) { struct node *node = ALLOC(node); if (type) { assert(!wire); node->type = getagent(type); node->code = code; free(type); } else if (code) { assert(!wire); node->code = code; } else { assert(wire); assert(!code); node->wire = getwire(wire); free(wire); } return node; }
int main(int argc, char *argv[]) { char *domdot, *verstr, *vertmp; int ppid = 0; int error; char *progname = NULL; /* "amd" */ char hostname[MAXHOSTNAMELEN + 1] = "localhost"; /* Hostname */ /* * Make sure some built-in assumptions are true before we start */ assert(sizeof(nfscookie) >= sizeof(u_int)); assert(sizeof(int) >= 4); /* * Set processing status. */ amd_state = Start; /* * Determine program name */ if (argv[0]) { progname = strrchr(argv[0], '/'); if (progname && progname[1]) progname++; else progname = argv[0]; } if (!progname) progname = "amd"; am_set_progname(progname); /* * Initialize process id. This is kept * cached since it is used for generating * and using file handles. */ am_set_mypid(); /* * Get local machine name */ if (gethostname(hostname, sizeof(hostname)) < 0) { plog(XLOG_FATAL, "gethostname: %m"); going_down(1); } hostname[sizeof(hostname) - 1] = '\0'; /* * Check it makes sense */ if (!*hostname) { plog(XLOG_FATAL, "host name is not set"); going_down(1); } /* * Initialize global options structure. */ init_global_options(); /* * Partially initialize hostd[]. This * is completed in get_args(). */ if ((domdot = strchr(hostname, '.'))) { /* * Hostname already contains domainname. * Split out hostname and domainname * components */ *domdot++ = '\0'; hostdomain = domdot; } xstrlcpy(hostd, hostname, sizeof(hostd)); am_set_hostname(hostname); /* * Setup signal handlers */ /* SIGINT: trap interrupts for shutdowns */ setup_sighandler(SIGINT, sigterm); /* SIGTERM: trap terminate so we can shutdown cleanly (some chance) */ setup_sighandler(SIGTERM, sigterm); /* SIGHUP: hangups tell us to reload the cache */ setup_sighandler(SIGHUP, sighup); /* * SIGCHLD: trap Death-of-a-child. These allow us to pick up the exit * status of backgrounded mounts. See "sched.c". */ setup_sighandler(SIGCHLD, sigchld); #ifdef HAVE_SIGACTION /* construct global "masked_sigs" used in nfs_start.c */ sigemptyset(&masked_sigs); sigaddset(&masked_sigs, SIGINT); sigaddset(&masked_sigs, SIGTERM); sigaddset(&masked_sigs, SIGHUP); sigaddset(&masked_sigs, SIGCHLD); #endif /* HAVE_SIGACTION */ /* * Fix-up any umask problems. Most systems default * to 002 which is not too convenient for our purposes */ orig_umask = umask(0); /* * Figure out primary network name */ getwire(&PrimNetName, &PrimNetNum); /* * Determine command-line arguments */ get_args(argc, argv); /* * Log version information. */ vertmp = get_version_string(); verstr = strtok(vertmp, "\n"); plog(XLOG_INFO, "AM-UTILS VERSION INFORMATION:"); while (verstr) { plog(XLOG_INFO, "%s", verstr); verstr = strtok(NULL, "\n"); } XFREE(vertmp); /* * Get our own IP address so that we can mount the automounter. We pass * localhost_address which could be used as the default localhost * name/address in amu_get_myaddress(). */ amu_get_myaddress(&myipaddr, gopt.localhost_address); plog(XLOG_INFO, "My ip addr is %s", inet_ntoa(myipaddr)); /* avoid hanging on other NFS servers if started elsewhere */ if (chdir("/") < 0) plog(XLOG_INFO, "cannot chdir to /: %m"); /* * Now check we are root. */ if (geteuid() != 0) { plog(XLOG_FATAL, "Must be root to mount filesystems (euid = %ld)", (long) geteuid()); going_down(1); } #ifdef HAVE_MAP_NIS /* * If the domain was specified then bind it here * to circumvent any default bindings that may * be done in the C library. */ if (gopt.nis_domain && yp_bind(gopt.nis_domain)) { plog(XLOG_FATAL, "Can't bind to NIS domain \"%s\"", gopt.nis_domain); going_down(1); } #endif /* HAVE_MAP_NIS */ if (!amuDebug(D_DAEMON)) ppid = daemon_mode(); /* * Lock process text and data segment in memory. */ if (gopt.flags & CFM_PROCESS_LOCK) { do_memory_locking(); } do_mapc_reload = clocktime(NULL) + gopt.map_reload_interval; /* * Register automounter with system. */ error = mount_automounter(ppid); if (error && ppid) kill(ppid, SIGALRM); #ifdef HAVE_FS_AUTOFS /* * XXX this should be part of going_down(), but I can't move it there * because it would be calling non-library code from the library... ugh */ if (amd_use_autofs) destroy_autofs_service(); #endif /* HAVE_FS_AUTOFS */ going_down(error); abort(); return 1; /* should never get here */ }
int main(int argc, char **argv) { char *networkName1, *networkNumber1; struct in_addr myipaddr; /* (An) IP address of this host */ char *testhost, *proto, *tmp_buf; int nv, ret; struct sockaddr_in *ip; struct hostent *hp = NULL; am_set_progname(argv[0]); if (gethostname(hostname, sizeof(hostname)) < 0) { perror(argv[0]); exit(1); } hostname[sizeof(hostname) - 1] = '\0'; /* get list of networks */ getwire(&networkName1, &networkNumber1); tmp_buf = print_wires(); if (tmp_buf) { fprintf(stderr, "%s", tmp_buf); XFREE(tmp_buf); } /* also print my IP address */ amu_get_myaddress(&myipaddr, NULL); fprintf(stderr, "My IP address is 0x%x.\n", (unsigned int) htonl(myipaddr.s_addr)); /* * NFS VERSION/PROTOCOL TESTS: * If argv[1] is specified perform nfs tests to that host, else use * localhost. */ if (argc > 1) testhost = argv[1]; else testhost = "localhost"; hp = gethostbyname(testhost); if (!hp) { fprintf(stderr, "NFS vers/proto failed: no such hostname \"%s\"\n", testhost); exit(1); } ip = (struct sockaddr_in *) xmalloc(sizeof(struct sockaddr_in)); memset((voidp) ip, 0, sizeof(*ip)); /* as per POSIX, sin_len need not be set (used internally by kernel) */ ip->sin_family = AF_INET; memmove((voidp) &ip->sin_addr, (voidp) hp->h_addr, sizeof(ip->sin_addr)); ip->sin_port = htons(NFS_PORT); fprintf(stderr, "NFS Version and protocol tests to host \"%s\"...\n", testhost); proto = "udp"; for (nv=2; nv<=3; ++nv) { fprintf(stderr, "\ttesting vers=%d, proto=\"%s\" -> ", nv, proto); ret = get_nfs_version(testhost, ip, nv, proto, 0); if (ret == 0) fprintf(stderr, "failed!\n"); else fprintf(stderr, "found version %d.\n", ret); } proto = "tcp"; for (nv=2; nv<=3; ++nv) { fprintf(stderr, "\ttesting vers=%d, proto=\"%s\" -> ", nv, proto); ret = get_nfs_version(testhost, ip, nv, proto, 0); if (ret == 0) fprintf(stderr, "failed!\n"); else fprintf(stderr, "found version %d.\n", ret); } exit(0); return 0; /* should never reach here */ }