int main( int argc, char *argv[]) { int c; int error; void *fs_hanp; size_t fs_hlen; char buf[BUFSIZ + 8]; Progname = argv[0]; fsname = NULL; while ((c = getopt(argc, argv, "vs:S:")) != EOF) { switch (c) { case 's': Sleep = atoi(optarg); break; case 'S': oldsid = atoi(optarg); break; case 'v': Verbose = 1; break; case '?': default: usage(Progname); exit(1); } } if (optind >= argc) { usage(Progname); exit(1); } fsname = argv[optind]; if (fsname == NULL) { usage(Progname); exit(1); } /* * Establish an exit handler */ error = establish_handler(); if (error) exit(1); /* * Init the dmapi, and get a filesystem handle so * we can set up our events */ if (oldsid) { sid = oldsid; } else { error = setup_dmapi(&sid); if (error) exit(1); } error = get_fs_handle(fsname, &fs_hanp, &fs_hlen); if (error) goto cleanup; /* * Set the event disposition so that our session will receive * all the events for the given file system */ error = set_disposition(sid, fs_hanp, fs_hlen); if (error) goto cleanup; /* * Enable monitoring for all events in the given file system */ error = set_events(sid, fs_hanp, fs_hlen); if (error) goto cleanup; /* * Set line buffering!! */ error = setvbuf(stdout, buf, _IOLBF, BUFSIZ); if (error) goto cleanup; /* * Now sit in an infinite loop, reporting on any events that occur. * The program is exited after a signal through exit_handler(). */ printf("\n"); event_loop(sid, 1 /*waitflag*/); /* * If we get here, cleanup after the event_loop failure */ cleanup: exit_handler(0); return(1); }
int main( int argc, char *argv[]) { int c; int error; dm_off_t size; char *fsname; dm_sessid_t sid; void *fs_hanp; size_t fs_hlen; char *sizep = "0"; Progname = argv[0]; size = 0; while ((c = getopt(argc, argv, "s:")) != EOF) { switch (c) { case 's': sizep = optarg; break; case '?': default: usage(Progname); exit(1); } } if (optind >= argc) { usage(Progname); exit(1); } /* * Verify the input size string is legit */ error = verify_size(sizep, &size); if (error) exit(1); fsname = argv[optind]; /* * Now we have our filesystem name and possibly a size threshold * to look for. Init the dmapi, and get a filesystem handle so * we can scan the filesystem */ error = setup_dmapi(&sid); if (error) exit(1); if (dm_path_to_fshandle(fsname, &fs_hanp, &fs_hlen) == -1) { errno_msg("Can't get filesystem handle"); exit(1); } /* * Get the attributes of all files in the filesystem */ error = scan_fs(sid, fs_hanp, fs_hlen, size); if (error) exit(1); /* * We're done, so we can shut down our session. */ if (dm_destroy_session(sid) == -1) { errno_msg("Can't close session"); exit(1); } return(0); }
int main( int argc, char *argv[]) { int c; int error; int mr_flag, alloc_flag, handle_flag, event_flag; void *hanp; size_t hlen; char *filename; dm_sessid_t sid; Progname = argv[0]; mr_flag = alloc_flag = handle_flag = event_flag = 0; while ((c = getopt(argc, argv, "maeh")) != EOF) { switch (c) { case 'm': mr_flag = 1; break; case 'a': alloc_flag = 1; break; case 'e': event_flag = 1; break; case 'h': handle_flag = 1; break; case '?': default: usage(Progname); exit(1); } } if (optind >= argc) { usage(Progname); exit(1); } filename = argv[optind]; if (filename == NULL) { usage(Progname); exit(1); } /* * Set up our link to the DMAPI, and get a handle for * the file we want to query */ error = setup_dmapi(&sid); if (error) exit(1); if (dm_path_to_handle(filename, &hanp, &hlen) == -1) { printf("Can't get handle for path %s", filename); error = 1; goto out; } printf("File %s:\n", filename); if (mr_flag) { error = mr_info(sid, hanp, hlen); if (error) { error = 1; goto out; } } if (alloc_flag) { error = alloc_info(sid, hanp, hlen); if (error) { error = 1; goto out; } } if (event_flag) { error = event_info(sid, hanp, hlen); if (error) { error = 1; goto out; } } if (handle_flag) { error = handle_info(sid, hanp, hlen); if (error) { error = 1; goto out; } } out: if (dm_destroy_session(sid)) { errno_msg("Can't shut down session"); error = 1; } return(error); }
int main( int argc, char *argv[]) { int c; int error; char *fsname, *logfile; dm_sessid_t sid; void *fs_hanp; size_t fs_hlen; Progname = argv[0]; fsname = NULL; logfile = NULL; while ((c = getopt(argc, argv, "vl:")) != EOF) { switch (c) { case 'v': Verbose = 1; break; case 'l': logfile = optarg; break; case '?': default: usage(Progname); exit(1); } } if (optind >= argc) { usage(Progname); exit(1); } fsname = argv[optind]; if (fsname == NULL) { usage(Progname); exit(1); } /* * If no logfile name is specified, we'll just send * all output to some file in /tmp */ if (logfile == NULL) logfile = LOG_DEFAULT; /* * Now we have our filesystem name and possibly a size threshold * to look for. Init the dmapi, and get a filesystem handle so * we can set up our events */ error = setup_dmapi(&sid); if (error) exit(1); if (dm_path_to_fshandle(fsname, &fs_hanp, &fs_hlen) == -1) { errno_msg("Can't get filesystem handle"); exit(1); } /* * Turn ourselves into a daemon */ error = mk_daemon(logfile); if (error) exit(1); /* * Set the event disposition so that our session will receive * the managed region events (read, write, and truncate) */ error = set_events(sid, fs_hanp, fs_hlen); if (error) exit(1); /* * Now wait forever for messages, spawning kids to * do the actual work */ event_loop(sid); return(0); }
int main(int argc, char **argv) { int c; // disable buffering for stdout and stderr streams setvbuf(stdout, NULL, _IONBF, 0); setvbuf(stderr, NULL, _IONBF, 0); // print out pid (for logger) printf("%d\n",getpid()); Progname = argv[0]; fsname = NULL; while ((c = getopt(argc, argv, "v")) != EOF) { switch (c) { case 'v': Verbose = 1; break; case '?': default: usage(Progname); exit(1); } } if ((argc-optind)!=2) { usage(Progname); exit(1); } DMAPI_SESSION_NAME = argv[optind++]; fsname = argv[optind]; // reset global state global_state=0; printf("Starting up yamssRecallDaemon\n"); // setup various signal handlers printf("Installing signal handlers\n"); setup_signals(); // initialize dmap printf("Initializing DMAPI\n"); setup_dmapi(); // setup event disposition for mount printf("Setting disposition for MOUNT events\n"); register_mount(); // recover existing tokens for mount events printf("Recovering existing tokens for MOUNT events\n"); token_recovery(DM_EVENT_MOUNT); // try to finalize inizialization finalize_init(); // start main loop printf("Starting main event loop\n"); event_loop(); return(0); }
int main( int argc, char *argv[]) { int c; int error; char *fsname; dm_sessid_t sid; void *fs_hanp; size_t fs_hlen; dm_attrname_t dmattr; size_t bufsz = 65536; dm_attrname_t *dmattrp = NULL; int verbose = V_PRINT; Progname = argv[0]; memset(&dmattr, 0, sizeof(dmattr)); while ((c = getopt(argc, argv, "a:b:vq")) != EOF) { switch (c) { case 'a': if (strlen(optarg) > (DM_ATTR_NAME_SIZE-1)){ printf("Arg for -a too long\n"); exit(1); } strcpy((char*)dmattr.an_chars, optarg); dmattrp = &dmattr; break; case 'b': bufsz = atoi(optarg); break; case 'v': verbose |= V_VERBOSE; break; case 'q': verbose &= ~V_PRINT; break; case '?': default: usage(Progname); exit(1); } } if (optind >= argc) { usage(Progname); exit(1); } fsname = argv[optind]; /* * Now we have our filesystem name and possibly a size threshold * to look for. Init the dmapi, and get a filesystem handle so * we can scan the filesystem */ error = setup_dmapi(&sid); if (error) exit(1); if (dm_path_to_fshandle(fsname, &fs_hanp, &fs_hlen) == -1) { errno_msg("Can't get filesystem handle"); exit(1); } /* * Get the attributes of all files in the filesystem */ error = scan_fs(sid, fs_hanp, fs_hlen, dmattrp, bufsz, verbose); if (error) exit(1); /* * We're done, so we can shut down our session. */ if (dm_destroy_session(sid) == -1) { errno_msg("Can't close session"); exit(1); } return(0); }