Ejemplo n.º 1
0
/**
 * Process the buffer
 * Return TRUE to exit program
 */
int process_buf(char **bufargs) {
    struct Command *cmd;
    int argc = 0;

    /*  cd command*/
    if (!strcmp(bufargs[0], "cd") && bufargs[0][2] == '\0') {
        set_cwd(bufargs[1]);
        return FALSE;
    }

    /* exit command */
    if (!strcmp(bufargs[0], "exit") && bufargs[0][4] == '\0') {
        return TRUE;
    }

    /* Get argc */
    while (bufargs[argc++] != ARR_END);

    /* Set up command and first process */
    cmd = init_command();
    cmd->procHead = init_process(argc * sizeof(char *));
    cmd->runningProcs++;

    /* Allocate arguments to their processes within the command */
    if (allocate_args(argc, bufargs, cmd) == TRUE) {
        /* Invalid command */
        free_command(NULL, cmd);
        return FALSE;
    }

    /* Add the command to the global commands */
    add_global(cmd);

    /* For each process in the command, fork it and set it up as running */
    fork_command(cmd);

    /* If foreground command, then wait on processes */
    if (cmd->type == FG) {
        wait_running(cmd);

        /* set the foreground command to null and clean it */
        globalCmd[FG] = NULL;
        free_command(NULL, cmd);
    }

    return FALSE;
}
Ejemplo n.º 2
0
static uint32_t synth_tts(const char *msg, srs_voice_notify_t notify,
                          void *user_data, void *api_data)
{
#if 1
    synth_t *synth = (synth_t *)api_data;
    uint32_t id;
    pid_t    pid, wfd;

    if (synth->active.pid) {
        errno = EBUSY;

        return SRS_VOICE_INVALID;
    }

    mrp_log_info("Synthesizing message '%s'.", msg);

    pid = fork_command(&wfd, synth->tts_argc - 1, synth->tts_argv + 1);

    if (pid > 0) {
        write(wfd, "G", 1);

        id = 1 | SYNTH_TYPE_ACTIVE;

        synth->active.pid = pid;
        synth->active.notify    = notify;
        synth->active.user_data = user_data;
        synth->active.id        = id;

        dprintf(wfd, "%s\n", msg);

        close(wfd);
    }
    else
        id = SRS_VOICE_INVALID;

#else
    uint32_t id = 0;

    char cmd[1024];
    snprintf(cmd, sizeof(cmd), "echo \"%s\" | /usr/bin/festival --tts", msg);
    system(cmd);
#endif

    return id;
}
Ejemplo n.º 3
0
static uint32_t synth_play_file(const char *path, srs_voice_notify_t notify,
                                void *user_data, void *api_data)
{
#if 1
    synth_t *synth = (synth_t *)api_data;
    uint32_t id;
    pid_t    pid, wfd;

    if (synth->active.pid) {
        errno = EBUSY;

        return SRS_VOICE_INVALID;
    }

    mrp_log_info("Playing sound file '%s'.", path);

    synth->play_argv[synth->play_argc] = (char *)path;

    pid = fork_command(&wfd, synth->play_argc, synth->play_argv + 1);

    if (pid > 0) {
        write(wfd, "G", 1);

        id = 1 | SYNTH_TYPE_ACTIVE;

        synth->active.pid = pid;
        synth->active.notify    = notify;
        synth->active.user_data = user_data;
        synth->active.id        = id;

        close(wfd);
    }
    else
        id = SRS_VOICE_INVALID;

#else
    uint32_t id = 0;
    char cmd[1024];

    snprintf(cmd, sizeof(cmd), "paplay %s", path);
    system(cmd);
#endif

    return id;
}
Ejemplo n.º 4
0
/* main */
int main(int argc, char **argv)
{
        char gid_string[5] = "";
        gid_t gid;
        int c;
        char command[COMM_LEN] = "";
        char llstat_file[100] = "";

        /* Checking for root*/
        if (getuid()) {
                fprintf(stderr, "Error: You need to be root\n");
                exit(1);
        }

        opterr = 0;
        /* Parsing command line switches */
        while ((c = getopt(argc, argv, "l:g:c:i:a:h")) != 1)
                switch (c) {
                        case 'l':
                                strcpy(llstat_file, optarg);
                                if (strlen(llstat_file) > LEN_OUT) {
                                        fprintf(stderr, "length of outfile file"
                                                " is too long\n");
                                        exit(1);
                                }
                                break;

                        /* When any value is written to vfs_track_gid, then VFS
                         * operation statistics are collected for all
                         * processes of that group ID.
                         * write_track_xid writes given <gid> in vfs_track_gid
                         * here. */
                        case 'g':
                                strcpy(gid_string, optarg);
                                get_command_from_argv(optind, argc, argv, "",
                                                      command);
                                gid = atoi(gid_string);

                                fork_command(TRACK_BY_GID, gid, command,
                                             llstat_file); 
                                return(0);

                        /* When any value is written to vfs_track_ppid, then VFS
                         * operation statistics are collected for all processes
                         * whose parents' PID is same as track_ppid.
                         *- write_track_xid writes pid to vfs_track_ppid here */
                        case 'c':
                                get_command_from_argv(optind, argc, argv,
                                                      optarg, command);
                                fork_command(TRACK_BY_PPID, 0, command,
                                             llstat_file);
                                return(0);

                        /* When a non-zero value is written to vfs_track_pid,
                         * then VFS operation statistics are collected for only
                         * that PID.Write_track_xid writes pid to vfs_track_pid
                         * here.Wei need to FORK a new process and EXEC it with
                         * given <command>. */
                        case 'i':
                                get_command_from_argv(optind, argc, argv,
                                                      optarg, command);
                                fork_command(TRACK_BY_PID, 0, command,
                                             llstat_file);
                                return(0);

                        /* When VFS operation statistics for all processes are
                         * to be collected, "0" is written to vfs_track_pid. */
                        case 'a':
                                get_command_from_argv(optind, argc, argv,
                                                      optarg, command);
                                fork_command(TRACK_FOR_ALL, 0, command,
                                             llstat_file);
                                return(0);

                        /* Help */
                        case 'h':
                                print_usage();
                                return(0);

                        default:
                                print_usage();
                                return(1);
                }
        return(0);
} /* main ends */