int main(void) { tprintf("%s", ""); int fds[2]; if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds)) perror_msg_and_skip("socketpair"); assert(0 == fds[0]); assert(1 == fds[1]); static const char w0_c[] = "012"; const char *w0_d = hexdump_strdup(w0_c); void *w0 = tail_memdup(w0_c, LENGTH_OF(w0_c)); static const char w1_c[] = "34567"; const char *w1_d = hexdump_strdup(w1_c); void *w1 = tail_memdup(w1_c, LENGTH_OF(w1_c)); static const char w2_c[] = "89abcde"; const char *w2_d = hexdump_strdup(w2_c); void *w2 = tail_memdup(w2_c, LENGTH_OF(w2_c)); static const char r0_c[] = "01234567"; const char *r0_d = hexdump_strdup(r0_c); static const char r1_c[] = "89abcde"; const char *r1_d = hexdump_strdup(r1_c); const struct iovec w_iov_[] = { { .iov_base = w0, .iov_len = LENGTH_OF(w0_c) }, { .iov_base = w1,
void initDynCtrls(int dev) { int i, err; /* try to add all controls listed above */ for ( i=0; i<LENGTH_OF(xu_ctrls); i++ ) { DBG("adding control for %d\n", i); errno=0; if ( (err=ioctl(dev, UVCIOC_CTRL_ADD, &xu_ctrls[i])) < 0 ) { if ( errno != EEXIST ) { DBG("uvcioc ctrl add error: errno=%d (retval=%d)\n", errno, err); } else { DBG("control %d already exists\n", i); } } } /* after adding the controls, add the mapping now */ for ( i=0; i<LENGTH_OF(xu_mappings); i++ ) { DBG("mapping controls for %s\n", xu_mappings[i].name); errno=0; if ((err=ioctl(dev, UVCIOC_CTRL_MAP, &xu_mappings[i])) < 0) { if (errno != EEXIST) { DBG("uvcioc ctrl map error: errno=%d (retval=%d)\n", errno, err); } else { DBG("mapping %d already exists\n", i); } } } }
int main(void) { tprintf("%s", ""); int fds[2]; if (pipe(fds)) perror_msg_and_fail("pipe"); assert(0 == fds[0]); assert(1 == fds[1]); static const char w0_c[] = "012"; const char *w0_d = hexdump_strdup(w0_c); void *w0 = tail_memdup(w0_c, LENGTH_OF(w0_c)); static const char w1_c[] = "34567"; const char *w1_d = hexdump_strdup(w1_c); void *w1 = tail_memdup(w1_c, LENGTH_OF(w1_c)); static const char w2_c[] = "89abcde"; const char *w2_d = hexdump_strdup(w2_c); void *w2 = tail_memdup(w2_c, LENGTH_OF(w2_c)); const struct iovec iov_[] = { { .iov_base = w0, .iov_len = LENGTH_OF(w0_c) }, { .iov_base = w1,
int main(int argc, char *argv[]) { int sock; struct sockaddr_in addr; int port = get_port(argc, argv); char server_address_string[16]; char buf[BUF_SIZE]; char repeat = 1; int id; set_address(argc, argv, server_address_string, LENGTH_OF(server_address_string)); srand(time(NULL)); id = rand(); sock = socket(AF_INET, SOCK_STREAM, 0); if(WRONG_SOC(sock)) { perror("socket"); exit(1); } addr.sin_family = AF_INET; addr.sin_port = htons(port); /* addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); */ addr.sin_addr.s_addr = inet_addr(server_address_string); if(connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) { perror("connect"); exit(2); } printf("%s:%d, ID: %d\n", server_address_string, port, id); send(sock, &id, sizeof(id), EMPTY_FLAGS); while(repeat) { printf("-> "); read_stdin(buf, LENGTH_OF(buf)); if(strlen(buf) == 0) continue; if(!strncmp(buf, "close", LENGTH_OF(buf))) repeat = 0; send_to(sock, buf); // download file if its exists if(strstr(buf, "download") && receive_int(sock)) { receive_file(sock); printf("%s\n", FILE_DOWNLOADED_MSG); continue; } // prints info or error mesages receive_and_print_msg(sock); } close(sock); return 0; }
int main(void) { const off_t offset = 0xdefaceddeadbeefLL; char *buf = tail_alloc(LEN); struct iovec *iov = tail_alloc(sizeof(*iov)); iov->iov_base = buf; iov->iov_len = LEN; (void) close(0); if (open("/dev/zero", O_RDONLY)) perror_msg_and_fail("open"); if (preadv(0, iov, 1, offset) != LEN) perror_msg_and_fail("preadv"); printf("preadv(0, "); print_iovec(iov, 1); printf(", 1, %lld) = %u\n", (long long) offset, LEN); if (preadv(0, iov, 1, -1) != -1) perror_msg_and_fail("preadv"); printf("preadv(0, [{iov_base=%p, iov_len=%zu}], 1, -1) = " "-1 EINVAL (%m)\n", iov->iov_base, iov->iov_len); if (preadv(0, NULL, 1, -2) != -1) perror_msg_and_fail("preadv"); printf("preadv(0, NULL, 1, -2) = -1 EINVAL (%m)\n"); if (preadv(0, iov, 0, -3) != -1) perror_msg_and_fail("preadv"); printf("preadv(0, [], 0, -3) = -1 EINVAL (%m)\n"); static const char tmp[] = "preadv-tmpfile"; int fd = open(tmp, O_RDWR | O_CREAT | O_TRUNC, 0600); if (fd < 0) perror_msg_and_fail("open"); if (unlink(tmp)) perror_msg_and_fail("unlink"); static const char w[] = "0123456789abcde"; if (write(fd, w, LENGTH_OF(w)) != LENGTH_OF(w)) perror_msg_and_fail("write"); static const char r0_c[] = "01234567"; static const char r1_c[] = "89abcde"; const unsigned int r_len = (LENGTH_OF(w) + 1) / 2; void *r0 = tail_alloc(r_len); const struct iovec r0_iov_[] = { { .iov_base = r0, .iov_len = r_len } };
int main(void) { tprintf("%s", ""); static char tmp[] = "preadv-pwritev-tmpfile"; if (open(tmp, O_CREAT|O_RDONLY|O_TRUNC, 0600) != 0) perror_msg_and_fail("creat: %s", tmp); if (open(tmp, O_WRONLY) != 1) perror_msg_and_fail("open: %s", tmp); if (unlink(tmp)) perror_msg_and_fail("unlink: %s", tmp); static const char w0_c[] = "012"; const char *w0_d = hexdump_strdup(w0_c); void *w0 = tail_memdup(w0_c, LENGTH_OF(w0_c)); const void *efault = w0 + LENGTH_OF(w0_c); static const char w1_c[] = "34567"; const char *w1_d = hexdump_strdup(w1_c); void *w1 = tail_memdup(w1_c, LENGTH_OF(w1_c)); static const char w2_c[] = "89abcde"; const char *w2_d = hexdump_strdup(w2_c); void *w2 = tail_memdup(w2_c, LENGTH_OF(w2_c)); long rc; rc = pwritev(1, efault, 42, 0); tprintf("pwritev(1, %p, 42, 0) = %ld %s (%m)\n", efault, rc, errno2name()); rc = preadv(0, efault, 42, 0); tprintf("preadv(0, %p, 42, 0) = %ld %s (%m)\n", efault, rc, errno2name()); static const char r0_c[] = "01234567"; const char *r0_d = hexdump_strdup(r0_c); static const char r1_c[] = "89abcde"; const char *r1_d = hexdump_strdup(r1_c); const struct iovec w_iov_[] = { { .iov_base = w0, .iov_len = LENGTH_OF(w0_c) }, { .iov_base = w1,
void GLTileEngine::genTexCoords() { // using POT texture dimensions for better compatibility with outdated hardware const int texWidth = 512; const int texHeight = 2048; this->tcxInc = 16.0 / texWidth; this->tcyInc = 16.0 / texHeight; double tcxPerTile = 18.0 / texWidth; double tcyPerTile = 18.0 / texHeight; double tcxOffset = 1.0 / texWidth; double tcyOffset = 1.0 / texHeight; int index = 0; for(int y=0; y<60; y++) { for(int x=0; x<16; x++) { this->texCoords[index++] = x * tcxPerTile + tcxOffset; this->texCoords[index++] = y * tcyPerTile + tcyOffset; } } assert(index == LENGTH_OF(this->texCoords)); }
/****************************************************************************** Description.: print a help message to stderr Input Value.: - Return Value: - ******************************************************************************/ void help(void) { int i; fprintf(stderr, " ---------------------------------------------------------------\n" \ " Help for input plugin..: "INPUT_PLUGIN_NAME"\n" \ " ---------------------------------------------------------------\n" \ " The following parameters can be passed to this plugin:\n\n" \ " [-d | --device ].......: video device to open (your camera)\n" \ " [-r | --resolution ]...: the resolution of the video device,\n" \ " can be one of the following strings:\n" \ " "); for(i = 0; i < LENGTH_OF(resolutions); i++) { fprintf(stderr, "%s ", resolutions[i].string); if((i + 1) % 6 == 0) fprintf(stderr, "\n "); } fprintf(stderr, "\n or a custom value like the following" \ "\n example: 640x480\n"); fprintf(stderr, " [-f | --fps ]..........: frames per second\n" \ " [-y | --yuv ]..........: enable YUYV format and disable MJPEG mode\n" \ " [-q | --quality ]......: JPEG compression quality in percent \n" \ " (activates YUYV format, disables MJPEG)\n" \ " [-m | --minimum_size ].: drop frames smaller then this limit, useful\n" \ " if the webcam produces small-sized garbage frames\n" \ " may happen under low light conditions\n" \ " [-n | --no_dynctrl ]...: do not initalize dynctrls of Linux-UVC driver\n" \ " [-l | --led ]..........: switch the LED \"on\", \"off\", let it \"blink\" or leave\n" \ " it up to the driver using the value \"auto\"\n" \ " [-s | --stop ].........: stop camera when no active outputs\n" \ " ---------------------------------------------------------------\n\n"); }
/****************************************************************************** Description.: copy a picture from testpictures.h and signal this to all output plugins, afterwards switch to the next frame of the animation. Input Value.: arg is not used Return Value: NULL ******************************************************************************/ void *worker_thread( void *arg ) { int i=0; /* set cleanup handler to cleanup allocated ressources */ pthread_cleanup_push(worker_cleanup, NULL); while( !pglobal->stop ) { /* copy JPG picture to global buffer */ pthread_mutex_lock( &pglobal->db ); i = (i + 1) % LENGTH_OF(pics->sequence); pglobal->size = pics->sequence[i].size; memcpy(pglobal->buf, pics->sequence[i].data, pglobal->size); /* signal fresh_frame */ pthread_cond_broadcast(&pglobal->db_update); pthread_mutex_unlock( &pglobal->db ); usleep(1000*delay); } IPRINT("leaving input thread, calling cleanup function now\n"); pthread_cleanup_pop(1); return NULL; }
void receive_and_print_msg(int sock) { unsigned int bytes_read; char buf[BUF_SIZE]; bytes_read = recv(sock, buf, LENGTH_OF(buf), 0); buf[bytes_read] = '\0'; printf("<- %s\n", buf); }
int receive_int(int sock) { unsigned int bytes_read; char buf[BUF_SIZE]; bytes_read = recv(sock, buf, LENGTH_OF(buf), 0); buf[bytes_read] = '\0'; return atoi(buf); }
void receive_file(int sock) { char file_name[BUF_SIZE]; int file_size, buf_size, bytes, readed_bytes = 0; FILE *f; //receive file name readed_bytes = recv(sock, file_name, LENGTH_OF(file_name), 0); file_name[readed_bytes] = '\0'; //receive file size file_size = receive_int(sock); //receive buf size buf_size = receive_int(sock); print_file_info(file_name, file_size, buf_size); if((f = fopen(file_name, "wb")) == NULL) { printf("Can't create file\n"); return; } char buf[buf_size]; do { bytes = recv(sock, buf, LENGTH_OF(buf), 0); printf("%i\n", bytes); // if last package if(bytes < buf_size - 1){ char new_buf[bytes]; strncpy(new_buf, buf, bytes); new_buf[bytes] = '\0'; fprintf(f, "%s", new_buf); } else { fprintf(f, "%s", buf); fseek(f, readed_bytes, SEEK_SET); } readed_bytes += bytes; printf("%i\n", readed_bytes); } while(bytes >= buf_size - 1); fclose(f); }
int main(void) { tprintf("%s", ""); int fds[2]; if (pipe(fds)) perror_msg_and_fail("pipe"); assert(0 == fds[0]); assert(1 == fds[1]); static const char w0_c[] = "012"; const char *w0_d = hexdump_strdup(w0_c); void *w0 = tail_memdup(w0_c, LENGTH_OF(w0_c)); const void *efault = w0 + LENGTH_OF(w0_c); static const char w1_c[] = "34567"; const char *w1_d = hexdump_strdup(w1_c); void *w1 = tail_memdup(w1_c, LENGTH_OF(w1_c)); static const char w2_c[] = "89abcde"; const char *w2_d = hexdump_strdup(w2_c); void *w2 = tail_memdup(w2_c, LENGTH_OF(w2_c)); assert(writev(1, efault, 42) == -1); tprintf("writev(1, [%p], 42) = -1 EFAULT (%m)\n", efault); assert(readv(0, efault, 42) == -1); tprintf("readv(0, %p, 42) = -1 EFAULT (%m)\n", efault); static const char r0_c[] = "01234567"; const char *r0_d = hexdump_strdup(r0_c); static const char r1_c[] = "89abcde"; const char *r1_d = hexdump_strdup(r1_c); const struct iovec w_iov_[] = { { .iov_base = w0, .iov_len = LENGTH_OF(w0_c) }, { .iov_base = w1,
static void dumpio(void) { static char tmp[] = "preadv2-pwritev2-tmpfile"; if (open(tmp, O_CREAT|O_RDONLY|O_TRUNC, 0600) != 0) perror_msg_and_fail("creat: %s", tmp); if (open(tmp, O_WRONLY) != 1) perror_msg_and_fail("open: %s", tmp); if (unlink(tmp)) perror_msg_and_fail("unlink: %s", tmp); static const char w0_c[] = "012"; const char *w0_d = hexdump_strdup(w0_c); void *w0 = tail_memdup(w0_c, LENGTH_OF(w0_c)); static const char w1_c[] = "34567"; const char *w1_d = hexdump_strdup(w1_c); void *w1 = tail_memdup(w1_c, LENGTH_OF(w1_c)); static const char w2_c[] = "89abcde"; const char *w2_d = hexdump_strdup(w2_c); void *w2 = tail_memdup(w2_c, LENGTH_OF(w2_c)); long rc; static const char r0_c[] = "01234567"; const char *r0_d = hexdump_strdup(r0_c); static const char r1_c[] = "89abcde"; const char *r1_d = hexdump_strdup(r1_c); const struct iovec w_iov_[] = { { .iov_base = w0, .iov_len = LENGTH_OF(w0_c) }, { .iov_base = w1,
/****************************************************************************** Description.: parse input parameters Input Value.: param contains the command line string and a pointer to globals Return Value: 0 if everything is ok ******************************************************************************/ int input_init(input_parameter *param) { char *argv[MAX_ARGUMENTS]={NULL}; int argc=1, i; pics = &picture_lookup[1]; if( pthread_mutex_init(&controls_mutex, NULL) != 0 ) { IPRINT("could not initialize mutex variable\n"); exit(EXIT_FAILURE); } /* convert the single parameter-string to an array of strings */ argv[0] = INPUT_PLUGIN_NAME; if ( param->parameter_string != NULL && strlen(param->parameter_string) != 0 ) { char *arg=NULL, *saveptr=NULL, *token=NULL; arg=(char *)strdup(param->parameter_string); if ( strchr(arg, ' ') != NULL ) { token=strtok_r(arg, " ", &saveptr); if ( token != NULL ) { argv[argc] = strdup(token); argc++; while ( (token=strtok_r(NULL, " ", &saveptr)) != NULL ) { argv[argc] = strdup(token); argc++; if (argc >= MAX_ARGUMENTS) { IPRINT("ERROR: too many arguments to input plugin\n"); return 1; } } } } } /* show all parameters for DBG purposes */ for (i=0; i<argc; i++) { DBG("argv[%d]=%s\n", i, argv[i]); } reset_getopt(); while(1) { int option_index = 0, c=0; static struct option long_options[] = \ { {"h", no_argument, 0, 0}, {"help", no_argument, 0, 0}, {"d", required_argument, 0, 0}, {"delay", required_argument, 0, 0}, {"r", required_argument, 0, 0}, {"resolution", required_argument, 0, 0}, {0, 0, 0, 0} }; c = getopt_long_only(argc, argv, "", long_options, &option_index); /* no more options to parse */ if (c == -1) break; /* unrecognized option */ if (c == '?'){ help(); return 1; } switch (option_index) { /* h, help */ case 0: case 1: DBG("case 0,1\n"); help(); return 1; break; /* d, delay */ case 2: case 3: DBG("case 2,3\n"); delay = atoi(optarg); break; /* r, resolution */ case 4: case 5: DBG("case 4,5\n"); for ( i=0; i < LENGTH_OF(picture_lookup); i++ ) { if ( strcmp(picture_lookup[i].resolution, optarg) == 0 ) { pics = &picture_lookup[i]; break; } } break; default: DBG("default case\n"); help(); return 1; } } pglobal = param->global; IPRINT("delay.............: %i\n", delay); IPRINT("resolution........: %s\n", pics->resolution); return 0; }
const struct iovec w_iov_[] = { { .iov_base = w0, .iov_len = LENGTH_OF(w0_c) }, { .iov_base = w1, .iov_len = LENGTH_OF(w1_c) }, { .iov_base = w2, .iov_len = LENGTH_OF(w2_c) } }; struct iovec *w_iov = tail_memdup(w_iov_, sizeof(w_iov_)); const unsigned int w_len = LENGTH_OF(w0_c) + LENGTH_OF(w1_c) + LENGTH_OF(w2_c); const struct msghdr w_mh_ = { .msg_iov = w_iov, .msg_iovlen = ARRAY_SIZE(w_iov_) }; const struct msghdr *w_mh = tail_memdup(&w_mh_, sizeof(w_mh_)); assert(sendmsg(1, w_mh, 0) == (int) w_len); close(1); tprintf("sendmsg(1, {msg_name=NULL, msg_namelen=0, msg_iov=" "[{\"%s\", %u}, {\"%s\", %u}, {\"%s\", %u}], msg_iovlen=%u" ", msg_controllen=0, msg_flags=0}, 0) = %u\n" " * %u bytes in buffer 0\n" " | 00000 %-49s %-16s |\n" " * %u bytes in buffer 1\n"
/****************************************************************************** Description.: parse input parameters Input Value.: param contains the command line string and a pointer to globals Return Value: 0 if everything is ok ******************************************************************************/ int input_init(input_parameter *param, int plugin_no) { int i; pics = &picture_lookup[1]; if(pthread_mutex_init(&controls_mutex, NULL) != 0) { IPRINT("could not initialize mutex variable\n"); exit(EXIT_FAILURE); } param->argv[0] = INPUT_PLUGIN_NAME; /* show all parameters for DBG purposes */ for(i = 0; i < param->argc; i++) { DBG("argv[%d]=%s\n", i, param->argv[i]); } reset_getopt(); while(1) { int option_index = 0, c = 0; static struct option long_options[] = { {"h", no_argument, 0, 0 }, {"help", no_argument, 0, 0}, {"d", required_argument, 0, 0}, {"delay", required_argument, 0, 0}, {"r", required_argument, 0, 0}, {"resolution", required_argument, 0, 0}, {0, 0, 0, 0} }; c = getopt_long_only(param->argc, param->argv, "", long_options, &option_index); /* no more options to parse */ if(c == -1) break; /* unrecognized option */ if(c == '?') { help(); return 1; } switch(option_index) { /* h, help */ case 0: case 1: DBG("case 0,1\n"); help(); return 1; break; /* d, delay */ case 2: case 3: DBG("case 2,3\n"); delay = atoi(optarg); break; /* r, resolution */ case 4: case 5: DBG("case 4,5\n"); for(i = 0; i < LENGTH_OF(picture_lookup); i++) { if(strcmp(picture_lookup[i].resolution, optarg) == 0) { pics = &picture_lookup[i]; break; } } break; default: DBG("default case\n"); help(); return 1; } } pglobal = param->global; IPRINT("delay.............: %i\n", delay); IPRINT("resolution........: %s\n", pics->resolution); return 0; }
const struct iovec iov_[] = { { .iov_base = w0, .iov_len = LENGTH_OF(w0_c) }, { .iov_base = w1, .iov_len = LENGTH_OF(w1_c) }, { .iov_base = w2, .iov_len = LENGTH_OF(w2_c) } }; const struct iovec *iov = tail_memdup(iov_, sizeof(iov_)); const unsigned int len = LENGTH_OF(w0_c) + LENGTH_OF(w1_c) + LENGTH_OF(w2_c); tprintf("vmsplice(1, [{\"%s\", %u}, {\"%s\", %u}" ", {\"%s\", %u}], %u, %s) = %u\n" " * %u bytes in buffer 0\n" " | 00000 %-49s %-16s |\n" " * %u bytes in buffer 1\n" " | 00000 %-49s %-16s |\n" " * %u bytes in buffer 2\n" " | 00000 %-49s %-16s |\n", w0_c, LENGTH_OF(w0_c), w1_c, LENGTH_OF(w1_c), w2_c, LENGTH_OF(w2_c), ARRAY_SIZE(iov_), "SPLICE_F_NONBLOCK", len, LENGTH_OF(w0_c), w0_d, w0_c, LENGTH_OF(w1_c), w1_d, w1_c, LENGTH_OF(w2_c), w2_d, w2_c);
/****************************************************************************** Description.: This function ializes the plugin. It parses the commandline- parameter and stores the default and parsed values in the appropriate variables. Input Value.: param contains among others the command-line string Return Value: 0 if everything is fine 1 if "--help" was triggered, in this case the calling programm should stop running and leave. ******************************************************************************/ int input_init(input_parameter *param, int id) { char *dev = "/dev/video0", *s; int width = 640, height = 480, fps = 5, format = V4L2_PIX_FMT_MJPEG, i; /* initialize the mutes variable */ if(pthread_mutex_init(&cams[id].controls_mutex, NULL) != 0) { IPRINT("could not initialize mutex variable\n"); exit(EXIT_FAILURE); } param->argv[0] = INPUT_PLUGIN_NAME; /* show all parameters for DBG purposes */ for(i = 0; i < param->argc; i++) { DBG("argv[%d]=%s\n", i, param->argv[i]); } /* parse the parameters */ reset_getopt(); while(1) { int option_index = 0, c = 0; static struct option long_options[] = { {"h", no_argument, 0, 0 }, {"help", no_argument, 0, 0}, {"d", required_argument, 0, 0}, {"device", required_argument, 0, 0}, {"r", required_argument, 0, 0}, {"resolution", required_argument, 0, 0}, {"f", required_argument, 0, 0}, {"fps", required_argument, 0, 0}, {"y", no_argument, 0, 0}, {"yuv", no_argument, 0, 0}, {"q", required_argument, 0, 0}, {"quality", required_argument, 0, 0}, {"m", required_argument, 0, 0}, {"minimum_size", required_argument, 0, 0}, {"n", no_argument, 0, 0}, {"no_dynctrl", no_argument, 0, 0}, {"l", required_argument, 0, 0}, {"led", required_argument, 0, 0}, {"s", no_argument, 0, 0}, {"stop", no_argument, 0, 0}, {0, 0, 0, 0} }; /* parsing all parameters according to the list above is sufficent */ c = getopt_long_only(param->argc, param->argv, "", long_options, &option_index); /* no more options to parse */ if(c == -1) break; /* unrecognized option */ if(c == '?') { help(); return 1; } /* dispatch the given options */ switch(option_index) { /* h, help */ case 0: case 1: DBG("case 0,1\n"); help(); return 1; break; /* d, device */ case 2: case 3: DBG("case 2,3\n"); dev = strdup(optarg); break; /* r, resolution */ case 4: case 5: DBG("case 4,5\n"); width = -1; height = -1; /* try to find the resolution in lookup table "resolutions" */ for(i = 0; i < LENGTH_OF(resolutions); i++) { if(strcmp(resolutions[i].string, optarg) == 0) { width = resolutions[i].width; height = resolutions[i].height; } } /* done if width and height were set */ if(width != -1 && height != -1) break; /* parse value as decimal value */ width = strtol(optarg, &s, 10); height = strtol(s + 1, NULL, 10); break; /* f, fps */ case 6: case 7: DBG("case 6,7\n"); fps = atoi(optarg); break; /* y, yuv */ case 8: case 9: DBG("case 8,9\n"); format = V4L2_PIX_FMT_YUYV; break; /* q, quality */ case 10: case 11: DBG("case 10,11\n"); format = V4L2_PIX_FMT_YUYV; gquality = MIN(MAX(atoi(optarg), 0), 100); break; /* m, minimum_size */ case 12: case 13: DBG("case 12,13\n"); minimum_size = MAX(atoi(optarg), 0); break; /* n, no_dynctrl */ case 14: case 15: DBG("case 14,15\n"); dynctrls = 0; break; /* l, led */ case 16: case 17:/* DBG("case 16,17\n"); if ( strcmp("on", optarg) == 0 ) { led = IN_CMD_LED_ON; } else if ( strcmp("off", optarg) == 0 ) { led = IN_CMD_LED_OFF; } else if ( strcmp("auto", optarg) == 0 ) { led = IN_CMD_LED_AUTO; } else if ( strcmp("blink", optarg) == 0 ) { led = IN_CMD_LED_BLINK; }*/ break; /* s, stop */ case 18: case 19: DBG("case 18,19\n"); stop_camera = 1; break; default: DBG("default case\n"); help(); return 1; } } DBG("input id: %d\n", id); cams[id].id = id; cams[id].pglobal = param->global; /* allocate webcam datastructure */ cams[id].videoIn = malloc(sizeof(struct vdIn)); if(cams[id].videoIn == NULL) { IPRINT("not enough memory for videoIn\n"); exit(EXIT_FAILURE); } memset(cams[id].videoIn, 0, sizeof(struct vdIn)); /* display the parsed values */ IPRINT("Using V4L2 device.: %s\n", dev); IPRINT("Desired Resolution: %i x %i\n", width, height); IPRINT("Frames Per Second.: %i\n", fps); IPRINT("Format............: %s\n", (format == V4L2_PIX_FMT_YUYV) ? "YUV" : "MJPEG"); if(format == V4L2_PIX_FMT_YUYV) IPRINT("JPEG Quality......: %d\n", gquality); IPRINT("Stop camera feat..: %d\n", stop_camera); DBG("vdIn pn: %d\n", id); /* open video device and prepare data structure */ if(init_videoIn(cams[id].videoIn, dev, width, height, fps, format, 1, cams[id].pglobal, id) < 0) { IPRINT("init_VideoIn failed\n"); closelog(); exit(EXIT_FAILURE); } /* * recent linux-uvc driver (revision > ~#125) requires to use dynctrls * for pan/tilt/focus/... * dynctrls must get initialized */ if(dynctrls) initDynCtrls(cams[id].videoIn->fd); enumerateControls(cams[id].videoIn, cams[id].pglobal, id); // enumerate V4L2 controls after UVC extended mapping return 0; }
/* static */ HRESULT Compatibility::Retarget(AssemblyName *pAssemblyName, AssemblyName **ppRetargetedAssemblyName, BOOL *pfIsRetargeted) { HRESULT hr = S_OK; BINDER_LOG_ENTER(W("Compatibility::Retarget")); IF_FALSE_GO(pAssemblyName != NULL); IF_FALSE_GO(ppRetargetedAssemblyName != NULL); BINDER_LOG_ASSEMBLY_NAME(W("source"), pAssemblyName); if (pfIsRetargeted) { *pfIsRetargeted = FALSE; } #ifdef FEATURE_CORESYSTEM // Apply retargeting only for strong-named culture neutral assemblies if (pAssemblyName->IsStronglyNamed() && pAssemblyName->GetDeNormalizedCulture().IsEmpty()) { ReleaseHolder<AssemblyName> pRetargetedAssemblyName; SString &simpleName = pAssemblyName->GetSimpleName(); AssemblyVersion *pAssemblyVersion = pAssemblyName->GetVersion(); SString publicKeyToken; TextualIdentityParser::BlobToHex(pAssemblyName->GetPublicKeyTokenBLOB(), publicKeyToken); // Perform linear search for matching assembly. Legacy Fusion also does that for (unsigned int i = 0; i < LENGTH_OF(arRetargetConfig); i++) { #ifdef FEATURE_LEGACYNETCF if (!RuntimeIsLegacyNetCF(0) && arRetargetConfig[i].fMangoOnly == TRUE) continue; #endif if (IsMatchingString(simpleName, arRetargetConfig[i].pwzSimpleName) && IsMatchingVersion(pAssemblyVersion, arRetargetConfig[i].pwzVersion) && IsMatchingString(publicKeyToken, arRetargetConfig[i].pwzPublicKeyToken)) { AssemblyVersion newAssemblyVersion; IF_FALSE_GO(newAssemblyVersion.SetVersion(arRetargetConfig[i].pwzNewVersion)); SAFE_NEW(pRetargetedAssemblyName, AssemblyName); if (arRetargetConfig[i].pwzNewSimpleName != NULL) { pRetargetedAssemblyName-> GetSimpleName().Set(arRetargetConfig[i].pwzNewSimpleName); } else { pRetargetedAssemblyName->GetSimpleName().Set(simpleName); } pRetargetedAssemblyName->SetVersion(&newAssemblyVersion); SBuffer newPublicKeyTokenBlob; SmallStackSString newPublicKeyToken(arRetargetConfig[i].pwzNewPublicKeyToken); TextualIdentityParser::HexToBlob(newPublicKeyToken, FALSE /* fValidateHex */, TRUE /* fIsToken */, newPublicKeyTokenBlob); pRetargetedAssemblyName->GetPublicKeyTokenBLOB().Set(newPublicKeyTokenBlob); BINDER_LOG_ASSEMBLY_NAME(W("retargeted"), pRetargetedAssemblyName); *ppRetargetedAssemblyName = pRetargetedAssemblyName.Extract(); if (pfIsRetargeted) { *pfIsRetargeted = TRUE; } GO_WITH_HRESULT(S_OK); } } // Create a clone without retargetable flag if (pAssemblyName->GetIsRetargetable()) { IF_FAIL_GO(pAssemblyName->Clone(&pRetargetedAssemblyName)); pRetargetedAssemblyName->SetIsRetargetable(FALSE); *ppRetargetedAssemblyName = pRetargetedAssemblyName.Extract(); } else { pAssemblyName->AddRef(); *ppRetargetedAssemblyName = pAssemblyName; } } else #endif // FEATURE_CORESYSTEM { pAssemblyName->AddRef(); *ppRetargetedAssemblyName = pAssemblyName; } Exit: BINDER_LOG_LEAVE_HR(W("Compatibility::Retarget"), hr); return hr; }
/****************************************************************************** Description.: This function ializes the plugin. It parses the commandline- parameter and stores the default and parsed values in the appropriate variables. Input Value.: param contains among others the command-line string Return Value: 0 if everything is fine 1 if "--help" was triggered, in this case the calling programm should stop running and leave. ******************************************************************************/ int input_init(const char * dev, context_t *context) { input_parameter *param = &context->input->param; context->stop = 0; context->cleaned = 0; input_t *input = context->input; char *s; int gquality = 80, minimum_size = 10; int width = 640, height = 480, fps = 5, fps_div = 1, format = V4L2_PIX_FMT_MJPEG, i; /* parse the parameters */ reset_getopt(); while (1) { int option_index = 0, c = 0; static struct option long_options[] = { { "r", required_argument, 0, 0 }, { "resolution", required_argument, 0, 0 }, { "f", required_argument, 0, 0 }, { "fps", required_argument, 0, 0 }, { "y", no_argument, 0, 0 }, { "yuv", no_argument, 0, 0 }, { "q", required_argument, 0, 0 }, { "quality", required_argument, 0, 0 }, { "m", required_argument, 0, 0 }, { "minimum_size", required_argument, 0, 0 }, { "s", required_argument, 0, 0 }, { "fpsdiv", required_argument, 0, 0 }, { 0, 0, 0, 0 } }; /* parsing all parameters according to the list above is sufficent */ c = getopt_long_only(param->argc, param->argv, "", long_options, &option_index); /* no more options to parse */ if (c == -1) break; /* dispatch the given options */ switch (option_index) { /* r, resolution */ case 0: case 1: width = -1; height = -1; /* try to find the resolution in lookup table "resolutions" */ for (i = 0; i < LENGTH_OF(resolutions); i++) { if (strcmp(resolutions[i].string, optarg) == 0) { width = resolutions[i].width; height = resolutions[i].height; } break; } /* done if width and height were set */ if (width != -1 && height != -1) break; /* parse value as decimal value */ width = strtol(optarg, &s, 10); height = strtol(s + 1, NULL, 10); break; /* f, fps */ case 2: case 3: fps = atoi(optarg); break; /* y, yuv */ case 4: case 5: format = V4L2_PIX_FMT_YUYV; break; /* q, quality */ case 6: case 7: format = V4L2_PIX_FMT_YUYV; gquality = MIN(MAX(atoi(optarg), 0), 100); break; /* m, minimum_size */ case 8: case 9: minimum_size = MAX(atoi(optarg), 0); break; case 10: case 11: fps_div = atoi(optarg); if (fps_div < 1) fps_div = 1; break; default: return -2; } } /* allocate webcam datastructure */ context->videoIn = (vdIn*) malloc(sizeof(struct vdIn)); if (context->videoIn == NULL) { PTRACE(0, "not enough memory for videoIn"); return -2; } memset(context->videoIn, 0, sizeof(struct vdIn)); input->frame_interval = 1000 * fps_div / fps; /* display the parsed values */ PTRACE(2, "Using V4L2 device.: "<< dev); PTRACE(2, "Desired Resolution: "<<width<<" x "<<height); PTRACE(2, "Frames Per Second.: "<<fps<<"/"<<fps_div); PTRACE(2, "Format............: "<< ((format == V4L2_PIX_FMT_YUYV) ? "YUV" : "MJPEG")); if (format == V4L2_PIX_FMT_YUYV) PTRACE(2, "JPEG Quality......: "<< gquality); context->minimum_size = minimum_size; /* open video device and prepare data structure */ if (init_videoIn(context->videoIn, dev, width, height, fps, fps_div, format, 1, input) < 0) { PTRACE(0, "init_VideoIn failed"); return -3; } return 0; }
}, { .iov_base = w1, .iov_len = LENGTH_OF(w1_c) }, { .iov_base = w2, .iov_len = LENGTH_OF(w2_c) } }; const struct iovec *w_iov = tail_memdup(w_iov_, sizeof(w_iov_)); assert(writev(1, w_iov, 0) == 0); tprintf("writev(1, [], 0) = 0\n"); assert(writev(1, w_iov + ARRAY_SIZE(w_iov_) - 1, 2) == -1); tprintf("writev(1, [{\"%s\", %u}, %p], 2) = -1 EFAULT (%m)\n", w2_c, LENGTH_OF(w2_c), w_iov + ARRAY_SIZE(w_iov_)); const unsigned int w_len = LENGTH_OF(w0_c) + LENGTH_OF(w1_c) + LENGTH_OF(w2_c); assert(writev(1, w_iov, ARRAY_SIZE(w_iov_)) == (int) w_len); close(1); tprintf("writev(1, [{\"%s\", %u}, {\"%s\", %u}" ", {\"%s\", %u}], %u) = %u\n" " * %u bytes in buffer 0\n" " | 00000 %-49s %-16s |\n" " * %u bytes in buffer 1\n" " | 00000 %-49s %-16s |\n" " * %u bytes in buffer 2\n" " | 00000 %-49s %-16s |\n", w0_c, LENGTH_OF(w0_c), w1_c, LENGTH_OF(w1_c),
/****************************************************************************** Description.: This function initializes the plugin. It parses the commandline- parameter and stores the default and parsed values in the appropriate variables. Input Value.: param contains among others the command-line string Return Value: 0 if everything is fine 1 if "--help" was triggered, in this case the calling programm should stop running and leave. ******************************************************************************/ int input_init(input_parameter *param) { char *argv[MAX_ARGUMENTS]={NULL}, *dev = "/dev/video0", *s; int argc=1, width=640, height=480, fps=5, format=V4L2_PIX_FMT_MJPEG, i; in_cmd_type led = IN_CMD_LED_AUTO; /* initialize the mutes variable */ if( pthread_mutex_init(&controls_mutex, NULL) != 0 ) { IPRINT("could not initialize mutex variable\n"); exit(EXIT_FAILURE); } /* convert the single parameter-string to an array of strings */ argv[0] = INPUT_PLUGIN_NAME; if ( param->parameter_string != NULL && strlen(param->parameter_string) != 0 ) { char *arg=NULL, *saveptr=NULL, *token=NULL; arg=(char *)strdup(param->parameter_string); if ( strchr(arg, ' ') != NULL ) { token=strtok_r(arg, " ", &saveptr); if ( token != NULL ) { argv[argc] = strdup(token); argc++; while ( (token=strtok_r(NULL, " ", &saveptr)) != NULL ) { argv[argc] = strdup(token); argc++; if (argc >= MAX_ARGUMENTS) { IPRINT("ERROR: too many arguments to input plugin\n"); return 1; } } } } } /* show all parameters for DBG purposes */ for (i=0; i<argc; i++) { DBG("argv[%d]=%s\n", i, argv[i]); } /* parse the parameters */ reset_getopt(); while(1) { int option_index = 0, c=0; static struct option long_options[] = \ { {"h", no_argument, 0, 0}, {"help", no_argument, 0, 0}, {"d", required_argument, 0, 0}, {"device", required_argument, 0, 0}, {"r", required_argument, 0, 0}, {"resolution", required_argument, 0, 0}, {"f", required_argument, 0, 0}, {"fps", required_argument, 0, 0}, {"y", no_argument, 0, 0}, {"yuv", no_argument, 0, 0}, {"q", required_argument, 0, 0}, {"quality", required_argument, 0, 0}, {"m", required_argument, 0, 0}, {"minimum_size", required_argument, 0, 0}, {"n", no_argument, 0, 0}, {"no_dynctrl", no_argument, 0, 0}, {"l", required_argument, 0, 0}, {"led", required_argument, 0, 0}, {0, 0, 0, 0} }; /* parsing all parameters according to the list above is sufficent */ c = getopt_long_only(argc, argv, "", long_options, &option_index); /* no more options to parse */ if (c == -1) break; /* unrecognized option */ if (c == '?'){ help(); return 1; } /* dispatch the given options */ switch (option_index) { /* h, help */ case 0: case 1: DBG("case 0,1\n"); help(); return 1; break; /* d, device */ case 2: case 3: DBG("case 2,3\n"); dev = strdup(optarg); break; /* r, resolution */ case 4: case 5: DBG("case 4,5\n"); width = -1; height = -1; /* try to find the resolution in lookup table "resolutions" */ for ( i=0; i < LENGTH_OF(resolutions); i++ ) { if ( strcmp(resolutions[i].string, optarg) == 0 ) { width = resolutions[i].width; height = resolutions[i].height; } } /* done if width and height were set */ if(width != -1 && height != -1) break; /* parse value as decimal value */ width = strtol(optarg, &s, 10); height = strtol(s+1, NULL, 10); break; /* f, fps */ case 6: case 7: DBG("case 6,7\n"); fps=atoi(optarg); break; /* y, yuv */ case 8: case 9: DBG("case 8,9\n"); format = V4L2_PIX_FMT_YUYV; break; /* q, quality */ case 10: case 11: DBG("case 10,11\n"); format = V4L2_PIX_FMT_YUYV; gquality = MIN(MAX(atoi(optarg), 0), 100); break; /* m, minimum_size */ case 12: case 13: DBG("case 12,13\n"); minimum_size = MAX(atoi(optarg), 0); break; /* n, no_dynctrl */ case 14: case 15: DBG("case 14,15\n"); dynctrls = 0; break; /* l, led */ case 16: case 17: DBG("case 16,17\n"); if ( strcmp("on", optarg) == 0 ) { led = IN_CMD_LED_ON; } else if ( strcmp("off", optarg) == 0 ) { led = IN_CMD_LED_OFF; } else if ( strcmp("auto", optarg) == 0 ) { led = IN_CMD_LED_AUTO; } else if ( strcmp("blink", optarg) == 0 ) { led = IN_CMD_LED_BLINK; } break; default: DBG("default case\n"); help(); return 1; } } /* keep a pointer to the global variables */ pglobal = param->global; /* allocate webcam datastructure */ videoIn = malloc(sizeof(struct vdIn)); if ( videoIn == NULL ) { IPRINT("not enough memory for videoIn\n"); exit(EXIT_FAILURE); } memset(videoIn, 0, sizeof(struct vdIn)); /* display the parsed values */ IPRINT("Using V4L2 device.: %s\n", dev); IPRINT("Desired Resolution: %i x %i\n", width, height); IPRINT("Frames Per Second.: %i\n", fps); IPRINT("Format............: %s\n", (format==V4L2_PIX_FMT_YUYV)?"YUV":"MJPEG"); if ( format == V4L2_PIX_FMT_YUYV ) IPRINT("JPEG Quality......: %d\n", gquality); /* open video device and prepare data structure */ if (init_videoIn(videoIn, dev, width, height, fps, format, 1) < 0) { IPRINT("init_VideoIn failed\n"); closelog(); exit(EXIT_FAILURE); } /* * recent linux-uvc driver (revision > ~#125) requires to use dynctrls * for pan/tilt/focus/... * dynctrls must get initialized */ if (dynctrls) initDynCtrls(videoIn->fd); /* * switch the LED according to the command line parameters (if any) */ input_cmd(led, 0); return 0; }
int __libc_start_main(int (*main) (int, char**, char**), int argc, char ** ubp_av, void (*init) (void), void (*fini) (void), void (*rtld_fini) (void), void (*stack_end)) { start_main_func orig_libc_start_main = dlsym (RTLD_NEXT, "__libc_start_main"); char *error_argv[] = { "doin", "error-kind", "error-file", "error-message", NULL }; const char *pid_string = getenv ("__DOIN_ATTACH_PID"); if (!pid_string) { error_argv[1] = "getenv"; error_argv[2] = "__DOIN_ATTACH_PID"; error_argv[3] = "no environment variable"; ubp_av = error_argv; main = doin_error_main; goto call_libc_start_main; } char path[PATH_MAX + 1]; for (unsigned i = 0; i < LENGTH_OF (s_namespaces); i++) { snprintf (path, PATH_MAX, "/proc/%s/ns/%s", pid_string, s_namespaces[i].name); /* * For error handling, we have to make sure that our function can * exit() properly, which means it has to be done inside main(). * We have to overwrite main with our own, which does the error * reporting. */ int fd = open (path, O_RDONLY); if (fd < 0) { if (errno == ENOENT) { /* Write with Unix syscalls, fprintf() cannot be used here. */ static const char warn_prefix[] = ": cannot join '"; static const char warn_suffix[] = "' namespace (unsupported by kernel)\n"; write (STDERR_FILENO, ubp_av[0], strlen (ubp_av[0])); write (STDERR_FILENO, warn_prefix, LENGTH_OF (warn_prefix)); write (STDERR_FILENO, s_namespaces[i].name, strlen (s_namespaces[i].name)); write (STDERR_FILENO, warn_suffix, LENGTH_OF (warn_suffix)); continue; } error_argv[1] = "cannot open"; error_argv[2] = path; error_argv[3] = strerror (errno); ubp_av = error_argv; main = doin_error_main; break; } if (setns (fd, s_namespaces[i].flag) < 0) { error_argv[1] = "setns()"; error_argv[2] = (char*) s_namespaces[i].name; error_argv[3] = strerror (errno); close (fd); ubp_av = error_argv; main = doin_error_main; break; } } call_libc_start_main: return (*orig_libc_start_main) (main, argc, ubp_av, init, fini, rtld_fini, stack_end); }
static int process_shebang(char *argv0, const char *const *cmdstr, size_t *cmdlen, char **cmdend, unsigned int *cmdsize) { HANDLE hfile; char buf[512]; unsigned int nn, t0; char *ptr, *ptr2; char *newargv[4]; char pbuffer[MAX_PATH]; char *filepart; static const char *shellnames[] = {"/bin/sh", "/bin/zsh", "/bin/ksh"}; static const char usrbinenv[] = "/usr/bin/env"; static const char usrbinpython[] = "/usr/bin/python"; static const char usrbinperl[] = "/usr/bin/perl"; static const char usrbintcl[] = "/usr/bin/tcl"; hfile = CreateFile(argv0, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hfile == INVALID_HANDLE_VALUE) return (-1); if (!ReadFile(hfile, buf, (DWORD)sizeof(buf), (DWORD *)&nn, NULL)) { CloseHandle(hfile); return (-1); } CloseHandle(hfile); if (!((nn >= 3) && (buf[0] == '#') && (buf[1] == '!'))) return (0); /* this code is more or less what zexecve() does */ for (t0 = 0; t0 != nn; t0++) if ((buf[t0] == '\n') || (buf[t0] == '\r')) break; while (isspace(buf[t0])) buf[t0--] = '\0'; buf[sizeof(buf)-1] = '\0'; /* @@@@ fails for "/b/s p/pgm" !!! */ for (ptr = buf + 2; *ptr && *ptr == ' '; ptr++) ; for (ptr2 = ptr; *ptr && *ptr != ' '; ptr++) ; /* ptr2 is the program name, ptr points to the args */ dbgprintf(PR_VERBOSE, "%s(): found \"!#\" program=[%s] arg ptr=[%s]\n", __FUNCTION__, ptr2, *ptr ? ptr + 1 : "NULL"); /* append to the cmdstr should have argv0 ('/' or '\' format ?) */ if (*ptr) { *ptr = '\0'; newargv[0] = ptr2; newargv[1] = ptr + 1; newargv[2] = argv0; } else { newargv[0] = ptr2; newargv[1] = argv0; newargv[2] = NULL; } newargv[3] = NULL; concat_args_and_quote((const char *const *)newargv, (char **)cmdstr, cmdlen, cmdend, cmdsize); *cmdend = '\0'; /* if ptr2 is a "well known" shell name set argv0 to our module name */ for (nn = 0; nn < LENGTH_OF(shellnames); nn++) { if (strcmp(ptr2, shellnames[nn]) == 0) { strcpy(argv0, gModuleName); return (1); } } if (strcmp(ptr2, usrbinenv) == 0) { SearchPath(NULL, "env.exe", NULL, sizeof(pbuffer), pbuffer, &filepart); strcpy(argv0, pbuffer); } else if (strcmp(ptr2, usrbinpython) == 0) { SearchPath(NULL, "python.exe", NULL, sizeof(pbuffer), pbuffer, &filepart); strcpy(argv0, pbuffer); } else if (strcmp(ptr2, usrbinperl) == 0) { SearchPath(NULL, "perl.exe", NULL, sizeof(pbuffer), pbuffer, &filepart); strcpy(argv0, pbuffer); } else if (strcmp(ptr2, usrbintcl) == 0) { SearchPath(NULL, "tcl.exe", NULL, sizeof(pbuffer), pbuffer, &filepart); strcpy(argv0, pbuffer); } else { char *exeptr; path_to_backslash(ptr2); strcpy(argv0, ptr2); /* if argv0 does not end with ".exe" add ".exe" */ exeptr = StrStrI(argv0, ".exe"); if ((exeptr == NULL) || (exeptr != strrchr(argv0, '.'))) { strcat(argv0, ".exe"); dbgprintf(PR_VERBOSE, "%s(): argv0 modified to [%s]\n", __FUNCTION__, argv0); } } return (1); }