Beispiel #1
0
int main(void) {
    char *sp;
    char input[512];
    int bytes_received = 0;
    fd_set fds;
    int ready_fds;
    struct timeval timeout;
    timeout.tv_sec = 0;
    timeout.tv_usec = 0;
    int ret;

    // cgc_read input
    while (1) {
        FD_ZERO(&fds);
        FD_SET(FD_FROM_MAIN, &fds);
        ret = fdwait(FD_FROM_MAIN + 1, &fds, NULL, &timeout, &ready_fds);
        bytes_received = receive_until_fd(FD_FROM_MAIN, input, sizeof(input), '\n');
        bytes_received = force_newline(input, sizeof(input), bytes_received);
        if (equals(input, "terminate\n")) {
            goto EXIT;
        }
        if (bytes_received > 0) {
            char *args[15];
            int i = 0;
            args[i++] = "mailsend";
            // parse input
            char *p = input;
            while (i < 14) {
                while(isspace(*p)) p++;
                if (!*p)
                    break;
                if (*p && !isspace(*p)) {
                    args[i++] = p;
                    while (*p && !isspace(*p)) p++;
                    *p++ = '\0';
                }
            }
            // Null terminate argument list
            args[i] = 0;

            mailsend(i, args);

            // Tell main program rsh is done
            send_all_fd(FD_TO_MAIN, "\0\n", 2);       
        }
    } 

    EXIT:
    // cgc_exit
    return 0;
}
Beispiel #2
0
int main(void) {
    char *sp;
    char input[512];
    int bytes_received = 0;
    fd_set fds;
    int ready_fds;
    struct timeval timeout;
    timeout.tv_sec = 0;
    timeout.tv_usec = 0;
    int ret;

    // Initialize user list
    srand();
    root_user = gen_random_user();
    num_users++;
    user *u = root_user;
    short_list = calloc(sizeof(short_list));
    short_list->object = root_user;
    for(int i=0; i<10; i++) {
        u->next = gen_random_user();
        u = u->next;
        num_users++;
    }

    // cgc_read input
    while (1) {
        FD_ZERO(&fds);
        FD_SET(FD_FROM_MAIN, &fds);
        ret = fdwait(FD_FROM_MAIN + 1, &fds, NULL, &timeout, &ready_fds);
        bytes_received = receive_until_fd(FD_FROM_MAIN, input, sizeof(input), '\n');
        bytes_received = force_newline(input, sizeof(input), bytes_received);
        if (equals(input, "terminate\n")) {
            goto EXIT;
        }
        if (bytes_received > 0) {
            lookupd();
            // Tell main program lookupd is done
            send_all_fd(FD_TO_MAIN, "\0\n", 2);       
        }
    } 

    EXIT:
    // cgc_exit
    return 0;
}
Beispiel #3
0
int send_all(char *buf, int length) {
  return send_all_fd(STDOUT, buf, length);
}