- struct udev *udev;
- static const struct option options[] = {
- { "add", no_argument, NULL, 'a' },
- { "remove", no_argument, NULL, 'r' },
- { "debug", no_argument, NULL, 'd' },
- { "help", no_argument, NULL, 'h' },
- {}
- };
- int argi;
- char *checkpoint, *us;
- int fd;
- int i;
- int ret = EXIT_SUCCESS;
- int prune = 0;
- char tmpdir[UTIL_PATH_SIZE];
-
- udev = udev_new();
- if (udev == NULL) {
- ret = EXIT_FAILURE;
- goto exit;
- }
-
- while (1) {
- int option;
-
- option = getopt_long(argc, argv, "ardh", options, NULL);
- if (option == -1)
- break;
-
- switch (option) {
- case 'a':
- prune = 0;
- break;
- case 'r':
- prune = 1;
- break;
- case 'd':
- debug = 1;
- break;
- case 'h':
- usage();
- goto exit;
- default:
- ret = 1;
- goto exit;
- }
- }
-
- argi = optind;
- if (argi + 2 > argc) {
- printf("Missing parameter(s)\n");
- ret = 1;
- goto exit;
- }
- checkpoint = argv[argi++];
- us = argv[argi++];
-
- if (signal(SIGALRM, sig_alrm) == SIG_ERR) {
- fprintf(stderr, "Cannot set SIGALRM: %s\n", strerror(errno));
- ret = 2;
- goto exit;
- }
-
- udev_list_node_init(&bunch);
-
- if (debug)
- fprintf(stderr, "Using checkpoint '%s'\n", checkpoint);
-
- util_strscpyl(tmpdir, sizeof(tmpdir), udev_get_run_path(udev), "/collect", NULL);
- fd = prepare(tmpdir, checkpoint);
- if (fd < 0) {
- ret = 3;
- goto out;
- }
-
- if (checkout(fd) < 0) {
- ret = 2;
- goto out;
- }
-
- for (i = argi; i < argc; i++) {
- struct udev_list_node *him_node;
- struct _mate *who;
-
- who = NULL;
- udev_list_node_foreach(him_node, &bunch) {
- struct _mate *him = node_to_mate(him_node);
-
- if (!strcmp(him->name, argv[i]))
- who = him;
- }
- if (!who) {
- struct _mate *him;
-
- if (debug)
- fprintf(stderr, "ID %s: not in database\n", argv[i]);
- him = malloc(sizeof (struct _mate));
- him->name = malloc(strlen(argv[i]) + 1);
- strcpy(him->name, argv[i]);
- him->state = STATE_NONE;
- udev_list_node_append(&him->node, &bunch);
- } else {
- if (debug)
- fprintf(stderr, "ID %s: found in database\n", argv[i]);
- who->state = STATE_CONFIRMED;
- }
- }
-
- if (prune)
- reject(us);
- else
- invite(us);
-
- if (debug) {
- everybody();
- fprintf(stderr, "Prune lists\n");
- }
- kickout();
-
- lseek(fd, 0, SEEK_SET);
- ftruncate(fd, 0);
- ret = missing(fd);
-
- lockf(fd, F_ULOCK, 0);
- close(fd);
+ struct udev *udev;
+ static const struct option options[] = {
+ { "add", no_argument, NULL, 'a' },
+ { "remove", no_argument, NULL, 'r' },
+ { "debug", no_argument, NULL, 'd' },
+ { "help", no_argument, NULL, 'h' },
+ {}
+ };
+ int argi;
+ char *checkpoint, *us;
+ int fd;
+ int i;
+ int ret = EXIT_SUCCESS;
+ int prune = 0;
+ char tmpdir[UTIL_PATH_SIZE];
+
+ udev = udev_new();
+ if (udev == NULL) {
+ ret = EXIT_FAILURE;
+ goto exit;
+ }
+
+ while (1) {
+ int option;
+
+ option = getopt_long(argc, argv, "ardh", options, NULL);
+ if (option == -1)
+ break;
+
+ switch (option) {
+ case 'a':
+ prune = 0;
+ break;
+ case 'r':
+ prune = 1;
+ break;
+ case 'd':
+ debug = 1;
+ break;
+ case 'h':
+ usage();
+ goto exit;
+ default:
+ ret = 1;
+ goto exit;
+ }
+ }
+
+ argi = optind;
+ if (argi + 2 > argc) {
+ printf("Missing parameter(s)\n");
+ ret = 1;
+ goto exit;
+ }
+ checkpoint = argv[argi++];
+ us = argv[argi++];
+
+ if (signal(SIGALRM, sig_alrm) == SIG_ERR) {
+ fprintf(stderr, "Cannot set SIGALRM: %s\n", strerror(errno));
+ ret = 2;
+ goto exit;
+ }
+
+ udev_list_node_init(&bunch);
+
+ if (debug)
+ fprintf(stderr, "Using checkpoint '%s'\n", checkpoint);
+
+ util_strscpyl(tmpdir, sizeof(tmpdir), udev_get_run_path(udev), "/collect", NULL);
+ fd = prepare(tmpdir, checkpoint);
+ if (fd < 0) {
+ ret = 3;
+ goto out;
+ }
+
+ if (checkout(fd) < 0) {
+ ret = 2;
+ goto out;
+ }
+
+ for (i = argi; i < argc; i++) {
+ struct udev_list_node *him_node;
+ struct _mate *who;
+
+ who = NULL;
+ udev_list_node_foreach(him_node, &bunch) {
+ struct _mate *him = node_to_mate(him_node);
+
+ if (!strcmp(him->name, argv[i]))
+ who = him;
+ }
+ if (!who) {
+ struct _mate *him;
+
+ if (debug)
+ fprintf(stderr, "ID %s: not in database\n", argv[i]);
+ him = malloc(sizeof (struct _mate));
+ him->name = malloc(strlen(argv[i]) + 1);
+ strcpy(him->name, argv[i]);
+ him->state = STATE_NONE;
+ udev_list_node_append(&him->node, &bunch);
+ } else {
+ if (debug)
+ fprintf(stderr, "ID %s: found in database\n", argv[i]);
+ who->state = STATE_CONFIRMED;
+ }
+ }
+
+ if (prune)
+ reject(us);
+ else
+ invite(us);
+
+ if (debug) {
+ everybody();
+ fprintf(stderr, "Prune lists\n");
+ }
+ kickout();
+
+ lseek(fd, 0, SEEK_SET);
+ ftruncate(fd, 0);
+ ret = missing(fd);
+
+ lockf(fd, F_ULOCK, 0);
+ close(fd);