}
/* Parse command line arguments. */
-static int parse_argv(int argc, char **argv,
- char **dso_name, char **device, int *reg, int *list)
+static int parse_argv(int argc, char **argv, char **dso_name_arg,
+ char **device_arg, int *reg, int *list)
{
int c;
const char *options = "d:hlru";
while ((c = getopt(argc, argv, options)) != -1) {
switch (c) {
case 'd':
- if (!(*dso_name = strdup(optarg)))
- exit(EXIT_FAILURE);
-
+ dso_name_arg = optarg;
break;
case 'h':
print_usage(argv[0]);
}
}
- if (!*dso_name && !(*dso_name = strdup(default_dso_name)))
- exit(EXIT_FAILURE);
-
if (optind >= argc) {
if (!*list) {
fprintf(stderr, "You need to specify a device.\n");
return 0;
}
- } else if (!(*device = strdup(argv[optind])))
- exit(EXIT_FAILURE);
+ } else
+ device_arg = argv[optind];
return 1;
}
int main(int argc, char **argv)
{
int list = 0, next = 0, ret, reg = default_reg;
- char *device = NULL, *device_arg, *dso_name = NULL, *dso_name_arg;
+ char *device, *device_arg = NULL, *dso_name, *dso_name_arg = NULL;
struct log_data *ldata;
- if (!parse_argv(argc, argv, &dso_name, &device, ®, &list))
+ if (!parse_argv(argc, argv, &dso_name_arg, &device_arg, ®, &list))
exit(EXIT_FAILURE);
- device_arg = device;
- dso_name_arg = dso_name;
+ if (device_arg){
+ if (!(device = strdup(device_arg)))
+ exit(EXIT_FAILURE);
+ } else
+ device = NULL;
+ if (dso_name_arg){
+ if (!(dso_name = strdup(dso_name_arg)))
+ exit(EXIT_FAILURE);
+ } else {
+ if (!(dso_name = strdup(default_dso_name)))
+ exit(EXIT_FAILURE);
+ }
if(!(ldata = malloc(sizeof(*ldata))))
exit(ENOMEM);
}
} while (!ret);
- if (dso_name)
- free(dso_name);
-
- if (device)
- free(device);
-
ret = (ret && device_arg) ? EXIT_FAILURE : EXIT_SUCCESS;
goto out;
}
out:
multilog_del_type(standard, ldata);
- if (device_arg)
- free(device_arg);
-
- if (dso_name_arg)
- free(dso_name_arg);
+ if (device)
+ free(device);
+ if (dso_name)
+ free(dso_name);
exit(ret);
}
enum event_type *events, int next)
{
int ret;
- char *dso_name_sav = NULL, *device_path_sav = NULL;
+ char *dso_name_arg = NULL, *device_path_arg = NULL;
struct daemon_message msg;
struct log_data *ldata;
- if (next) {
- dso_name_sav = *dso_name;
- device_path_sav = *device_path;
- }
-
if (!(ret = do_event(next ? CMD_GET_NEXT_REGISTERED_DEVICE :
CMD_GET_REGISTERED_DEVICE,
&msg, *dso_name, *device_path, *events)))
- ret = parse_message(&msg, dso_name, device_path, events);
-
- if (dso_name_sav)
- free(dso_name_sav);
-
- if (device_path_sav)
- free(device_path_sav);
+ ret = parse_message(&msg, dso_name_arg, device_path_arg,
+ events);
+
+ if (next){
+ if (*dso_name)
+ free(*dso_name);
+ if (*device_path)
+ free(*device_path);
+ *dso_name = dso_name_arg;
+ *device_path = device_path_arg;
+ } else {
+ if (!(*dso_name))
+ *dso_name = dso_name_arg;
+ if (!(*device_path))
+ *device_path = device_path_arg;
+ }
return ret;
}