Exemple #1
0
int main(int argc, char **argv)
{

        int c;
        int opt_index = 0;
        TelemPostDaemon daemon;

        struct option opts[] = {
                { "config_file", 1, NULL, 'f' },
                { "help", 0, NULL, 'h' },
                { "version", 0, NULL, 'V' },
                { NULL, 0, NULL, 0 }
        };

        while ((c = getopt_long(argc, argv, "f:hV", opts, &opt_index)) != -1) {
                switch (c) {
                        case 'f':
                                if (tm_set_config_file(optarg) != 0) {
                                    telem_log(LOG_ERR, "Configuration file"
                                                  " path not valid\n");
                                    exit(EXIT_FAILURE);
                                }
                                break;
                        case 'V':
                                printf(PACKAGE_VERSION "\n");
                                exit(EXIT_SUCCESS);
                        case 'h':
                                print_usage(argv[0]);
                                exit(EXIT_SUCCESS);
                        case '?':
                                print_usage(argv[0]);
                                exit(EXIT_FAILURE);
                }
        }

        initialize_daemon(&daemon);

        daemon.current_spool_size = get_spool_dir_size();

        /* When path activated this will process
         * the activating message or previously
         * spooled data */
        staging_records_loop(&daemon);

        /* This function is blocking, it will
        * block until a signal is received */
        run_daemon(&daemon);

        close_daemon(&daemon);

        return 0;
}
Exemple #2
0
int main(int argc, char **argv)
{
        uint32_t severity = 1;
        uint32_t payload_version = 1;
        char classification[20] = "misc/life/hello";
        struct telem_ref *tm_handle = NULL;
        char *payload2;

        // Following vars are for arg parsing.
        int c;
        char *cfile = NULL;
        int opt_index = 0;
        int ret = 0;

        struct option opts[] = {
                { "cfile", 1, NULL, 'f' },
                { "help", 0, NULL, 'h' },
                { "version", 0, NULL, 'V' },
                { NULL, 0, NULL, 0 }
        };

        while ((c = getopt_long(argc, argv, "f:hV", opts, &opt_index)) != -1) {
                switch (c) {
                        case 'f':
                                if (asprintf(&cfile, "%s", (char *)optarg) < 0) {
                                        exit(EXIT_FAILURE);
                                }

                                struct stat buf;
                                ret = stat(cfile, &buf);

                                /* check if the file exists and is a regular file */
                                if (ret == -1 || !S_ISREG(buf.st_mode)) {
                                        exit(EXIT_FAILURE);
                                }

                                tm_set_config_file(cfile);
                                break;
                        case 'h':
                                print_usage(argv[0]);
                                exit(EXIT_SUCCESS);
                        case 'V':
                                printf(PACKAGE_VERSION "\n");
                                exit(EXIT_SUCCESS);
                        case '?':
                                exit(EXIT_FAILURE);
                }
        }

        if (asprintf(&payload2, "hello\n") < 0) {
                exit(EXIT_FAILURE);
        }

        tm_handle = tm_create_record(severity, classification, payload_version);
        tm_set_payload(tm_handle,  payload2);

        free(payload2);

        if (!tm_send_record(tm_handle)) {
                printf("Failed to send record to daemon.\n");
                return 1;
        } else {
                printf("Successfully sent record to daemon.\n");
                return 0;
        }

        tm_free_record(tm_handle);
        tm_handle = NULL;
}