void logger_init() { Logger *l = &logger; l->fname = get_logdir(); l->fd = open(l->fname, O_CREAT | O_APPEND | O_WRONLY, 0777); if (l->fd < 0) { fprintf(stderr, "could not open logger fh: %s", strerror(errno)); exit(1); } logger_log("logger initialized"); }
int usage(const int retval) { char *logdir; if (retval != EXIT_SUCCESS) { fprintf(stderr, "\nType \"%s --help\" for help screen. " "Returning with value %d.\n", progname, retval); return retval; } logdir = get_logdir(NULL); puts(""); if (verbose_level(0) >= 1) { print_version(); puts(""); } printf("Usage: %s [options]\n", progname); printf("\n"); printf("Generates one or more UUIDs and stores it to a log file with " "optional \n" "comment or tag/category.\n"); printf("\n"); printf("Options:\n"); printf("\n"); printf(" -c x, --comment x\n" " Store comment x in the log file. If \"-\" is specified as " "comment, the \n" " program will read the comment from stdin. Two hyphens " "(\"--\") as a \n" " comment opens the editor defined in the environment " "variable \n" " %s to edit the message. If %s is " "not defined, \n" " EDITOR is read, if not defined, \"%s\" is called, it " "should exist \n" " everywhere. It may not, but it should.\n", ENV_EDITOR, ENV_EDITOR, STD_EDITOR); printf(" -h, --help\n" " Show this help.\n"); printf(" --license\n" " Print the software license.\n"); printf(" -l x, --logdir x\n" " Store log files in directory x.\n" " If the %s environment variable is defined, " "that value is \n" " used. Otherwise the value \"$HOME/uuids\" is used.\n" " Current default: %s\n", ENV_LOGDIR, logdir); printf(" -m, --random-mac\n" " Don't use the hardware MAC address, generate a random " "address field.\n"); printf(" -n x, --count x\n" " Print and store x UUIDs.\n"); printf(" -q, --quiet\n" " Be more quiet. Can be repeated to increase silence.\n"); printf(" --raw\n" " Don't convert <txt> element to XML. When using this " "option, it is \n" " expected that the value of the -c/--comment option is " "valid XML, \n" " otherwise it will create corrupted log files.\n"); printf(" --rcfile X\n" " Use file X instead of '%s/%s'.\n", getenv("HOME"), STD_RCFILE); printf(" --self-test\n" " Run various internal self tests and exit.\n"); printf(" -t x, --tag x\n" " Use x as tag (category).\n"); printf(" -v, --verbose\n" " Increase level of verbosity. Can be repeated.\n"); printf(" --version\n" " Print version information.\n"); printf(" -w x, --whereto x\n" " x is a string which decides where the UUID will be " "written:\n" " The string contains 'e' - stderr\n" " The string contains 'o' - stdout\n" " All other characters will be ignored. Examples:\n" " e\n" " Send to stderr.\n" " eo\n" " Send to both stdout and stderr.\n" " a\n" " Synonym for eo.\n" " n\n" " Don't output anything.\n" " Default: \"o\"\n"); printf("\n"); printf("If the %s environment variable is defined by " "sess(1) or another \n" "program, the value is logged if it is an UUID.\n", ENV_SESS); printf("\n"); printf("A different hostname can be specified in the environment " "variable \n" "%s, or in the rc file %s/%s with the format \n" "\"hostname = xxx\".\n", ENV_HOSTNAME, getenv("HOME"), STD_RCFILE); printf("To use a specific MAC address all the time, add it to the rc " "file using \n" "the format \"macaddr = xxxxxxxxxxxx\".\n"); printf("\n"); free(logdir); return retval; }