コード例 #1
0
ファイル: fifotest2.c プロジェクト: Linutronix/libmutexwrap
int child_process (void)
{
	int fd;
	char buf [100];

	/* Setup a signal handler for SIGINT */
	signal (SIGINT, int_proc);
	signal (SIGTERM, int_proc);

	if (verbose)
		printf ("child start\n");

	fd = fifo_open (FILENAME, 0);
	if (fd == -1)
		return EXIT_FAILURE;

	while (!stop)
	{
		memset (buf, 0, 100);
		fifo_read (fd, buf, 100);
		printf ("read: >%s<\n", buf);
		fflush (stdout);
	}

	fifo_close (fd);
	if (verbose)
		printf ("child done\n");

	return EXIT_SUCCESS;
}
コード例 #2
0
ファイル: info.c プロジェクト: anrl/gini3
/*
 * This function basically sets up the .port (for wireshark use)
 */
void infoInit(char *rpath, char *rname)
{
	int fd, status;

	sprintf(iconf.path, "%s/%s.%s", rpath, rname, "info");
	iconf.updateinterval = 10;                    // set default update time to 10 sec

 	if (fifo_exists(iconf.path, 1))
 	{
 		verbose(2, "[infoInit]:: WARNING! existing FIFO %s removed .. creating a new one ", iconf.path);
 		remove(iconf.path);

		if (iconf.threadid != 0)
			pthread_cancel(iconf.id);
 	}

 	if ((fd = fifo_open(iconf.path, S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH, 1, &(iconf.id))) == -1)
 	{
 		error("[infoInit]:: unable to create socket .. %s", iconf.path);
 		return;
 	}

	iconf.qtargets = list_create(NULL);

	status = pthread_create(&(iconf.threadid), NULL, (void *)infoHandler, (void *)NULL);
	if (status != 0)
		error("Unable to create the info handler thread... ");
	return;
}
コード例 #3
0
static void *
fifo_output_init(G_GNUC_UNUSED const struct audio_format *audio_format,
		 const struct config_param *param,
		 GError **error)
{
	struct fifo_data *fd;
	char *value, *path;

	value = config_dup_block_string(param, "path", NULL);
	if (value == NULL) {
		g_set_error(error, fifo_output_quark(), errno,
			    "No \"path\" parameter specified");
		return NULL;
	}

	path = parsePath(value);
	g_free(value);
	if (!path) {
		g_set_error(error, fifo_output_quark(), errno,
			    "Could not parse \"path\" parameter");
		return NULL;
	}

	fd = fifo_data_new();
	fd->path = path;

	if (!fifo_open(fd, error)) {
		fifo_data_free(fd);
		return NULL;
	}

	return fd;
}
コード例 #4
0
ファイル: mark1-rpi.c プロジェクト: andygikling/logi-tools
static PyObject* fifoOpen(PyObject* self, PyObject* arg)
{
	unsigned int fifo_id ;
	unsigned int returnVal ;
	if(!PyArg_ParseTuple(arg, "l", &fifo_id))
		return NULL;					
	returnVal = fifo_open(fifo_id);
	return Py_BuildValue("l", returnVal) ;
}
コード例 #5
0
ファイル: imfs_fifo.c プロジェクト: zhongweiy/rtems
static int IMFS_fifo_open(
    rtems_libio_t *iop,
    const char    *pathname,
    int            oflag,
    mode_t         mode
)
{
    IMFS_jnode_t *jnode = iop->pathinfo.node_access;

    int err = fifo_open(&JNODE2PIPE(jnode), iop);
    IMFS_FIFO_RETURN(err);
}
コード例 #6
0
int IMFS_fifo_open(
  epos_libio_t *iop,
  const char    *pathname,
  uint32_t       flag,
  uint32_t       mode
)
{
  IMFS_jnode_t *jnode = iop->file_info;

  int err = fifo_open(&JNODE2PIPE(jnode), iop);
  IMFS_FIFO_RETURN(err);
}
コード例 #7
0
ファイル: input_memory.c プロジェクト: AshirogiMaxx/fpga-cam
/******************************************************************************
Description.: starts the worker thread and allocates memory
Input Value.: -
Return Value: 0
******************************************************************************/
int input_run(int id)
{
    pglobal->in[id].buf = malloc(256 * 1024);
    if(pglobal->in[id].buf == NULL) {
        fprintf(stderr, "could not allocate memory\n");
        exit(EXIT_FAILURE);
    }
    fifo_open();
    if( fifo_open() < 0){
    	fprintf(stderr, "could not open fifo !  (try sudo ...)\n");
	exit(EXIT_FAILURE);
    }

    if(pthread_create(&worker, 0, worker_thread, NULL) != 0) {
        free(pglobal->in[id].buf);
        fprintf(stderr, "could not start worker thread\n");
        exit(EXIT_FAILURE);
    }
    pthread_detach(worker);

    return 0;
}
コード例 #8
0
ファイル: main.c プロジェクト: geek77/wine-steam-bridge
void 
    onclient(HANDLE p, void *params)
{
    HANDLE hThreadP2F = NULL;
    DWORD  tidP2F = 0;
    DWORD  tidF2P = 0;
    HANDLE hThreadF2P = NULL;
    params_t *prms;
    void *f;    
    pipe_t *redirect = (pipe_t*)malloc(sizeof(pipe_t));
    WINE_TRACE("\n");
    prms = (params_t*)params;
    f = fifo_open(prms->fifo);
    if (f == NULL) return_with_error("could not open fifo '%s'\n", prms->fifo);
    redirect->w = p;
    redirect->l = f;    
    hThreadP2F = CreateThread(NULL,0,read_pipe,(LPVOID)redirect,0,&tidP2F);
    if (hThreadP2F==NULL) return_with_error("could not create read_pipe thread\n");
    hThreadF2P = CreateThread(NULL,0,read_fifo,(LPVOID)redirect,0,&tidF2P);
    if (hThreadF2P==NULL) return_with_error("could not create read_fifo thread\n");
}
コード例 #9
0
ファイル: fifo.c プロジェクト: hsgg/quark
static gboolean
fifo_read (GIOChannel *chan, GIOCondition cond, gpointer data)
{
    char *command;
    gsize term;
    GError *err;
    gboolean ret;

    g_static_mutex_lock (&main_fifo_mutex);

    err = NULL;

    if (cond & G_IO_IN) {
        while (g_io_channel_read_line (chan, &command, NULL, &term, &err) ==
                G_IO_STATUS_NORMAL) {
            command[term] = '\0';
            fifo_execute (command);
            g_free (command);
        }
        if (err) {
            g_warning ("error reading fifo: %s", err->message);
            g_error_free (err);
        }
    }

    if (cond & G_IO_HUP || cond & G_IO_ERR) {
        fifo_close ();
        if (!fifo_open ()) {
            g_critical ("failed to reopen fifo");
            main_quit ();
        }
        ret = FALSE; /* remove me from the watch */
    } else
        ret = TRUE;

    g_static_mutex_unlock (&main_fifo_mutex);

    return ret;
}
コード例 #10
0
ファイル: main.c プロジェクト: hsgg/quark
int
main (int argc, char **argv)
{
#ifdef USE_GCONF
    GConfClient *gconf;
#endif

    char *dir;
    struct sigaction action;
    sigset_t sigset;

    main_status = QUARK_STARTING;

    /* initialize the locale */
    if (!setlocale(LC_ALL, ""))
	g_warning("Couldn't set locale from environment.\n");
    bindtextdomain(PACKAGE_NAME, LOCALEDIR);
    bind_textdomain_codeset(PACKAGE_NAME, "UTF-8");
    textdomain(PACKAGE_NAME);

    /* set up signal handler */
    sigemptyset (&sigset);
    action.sa_handler = signal_handler;
    action.sa_mask = sigset;
    action.sa_flags = SA_NOCLDSTOP;
    sigaction (SIGTERM, &action, (struct sigaction *) NULL);
    sigaction (SIGINT, &action, (struct sigaction *) NULL);
    sigaction (SIGHUP, &action, (struct sigaction *) NULL);

    g_type_init ();
    gnome_vfs_init ();

#ifdef USE_GCONF
    gconf = gconf_client_get_default ();
    gconf_client_add_dir (gconf, QUARK_GCONF_ROOT,
                          GCONF_CLIENT_PRELOAD_RECURSIVE, NULL);
    gconf_client_notify_add (gconf, QUARK_GCONF_ROOT, config_changed, NULL,
                             NULL, NULL);
#endif

    /* make the directory we use in ~ */
    dir = g_build_filename (g_get_home_dir(), ".quark", NULL);
    mkdir (dir, S_IRWXU|S_IRWXG|S_IRWXO);
    g_free (dir);

    loop = g_main_loop_new (NULL, FALSE);

    if (!fifo_open ()) {
        g_critical("failed to open fifo");
        return 1;
    }

    music_init ();

    g_static_mutex_lock (&main_mutex);
    playlist_init ();
#ifdef USE_GCONF
    config_load (gconf);
#endif
    main_status = QUARK_RUNNING;
    g_static_mutex_unlock (&main_mutex);

    g_main_loop_run (loop);

    g_static_mutex_lock (&main_mutex);
    main_status = QUARK_EXITING;
#ifdef USE_GCONF
    config_save (gconf);
#endif
    playlist_destroy ();
    g_static_mutex_unlock (&main_mutex);

    music_destroy ();

    fifo_destroy ();
    g_main_loop_unref (loop);
#ifdef USE_GCONF
    g_object_unref (G_OBJECT (gconf));
#endif

    gnome_vfs_shutdown ();

    return 0;
}
コード例 #11
0
int main(int argc, char *argv[]) {
    enum                    { MAX_RETRIES = 100 };
    enum                    { SLEEP_US    = 1000 };
    bool                      attach = false;
    _xcc_status               cc;
    bool                      client = false;
    int                       count;
    int                       count_read;
    int                       count_written;
    bool                      dif = false;
    double                    dloop;
    double                    dms;
    double                    dsec;
    int                       err;
    bool                      exec = false;
    int                       ferr;
    bool                      fin = false;
    MS_Mon_Process_Info_Type  info;
    MS_Mon_Process_Info_Type *infop;
    int                       inx;
    int                       inx2;
    int                       inx3;
    short                     len;
    short                     lerr;
    short                     lerr2;
    int                       loop = 10;
    int                       max;
    int                       nid;
    pid_t                     pid;
    int                       sargc;
    ssize_t                   size;
    int                       snid;
    int                       spid;
    bool                      startup = false;
    xzsys_ddl_smsg_def       *sys_msgp = (xzsys_ddl_smsg_def *) recv_buffer;
    int                       sys_msg;
    int                       sys_msg_count;
    bool                      verbose = false;
    TAD                       zargs[] = {
      { "-attach",    TA_Bool, TA_NOMAX,    &attach    },
      { "-client",    TA_Bool, TA_NOMAX,    &client    },
      { "-dif",       TA_Bool, TA_NOMAX,    &dif       },
      { "-exec",      TA_Bool, TA_NOMAX,    &exec      },
      { "-loop",      TA_Int,  TA_NOMAX,    &loop      },
      { "-maxsp",     TA_Int,  TA_NOMAX,    &maxsp     },
      { "-server",    TA_Ign,  TA_NOMAX,    NULL       },
      { "-startup",   TA_Bool, TA_NOMAX,    &startup   },
      { "-trace",     TA_Bool, TA_NOMAX,    &trace     },
      { "-v",         TA_Bool, TA_NOMAX,    &verbose   },
      { "-verbose",   TA_Ign,  TA_NOMAX,    NULL       },
      { "",           TA_End,  TA_NOMAX,    NULL       }
    };

    arg_proc_args(zargs, false, argc, argv);
    sprintf(fifo1, "%s-%s", FIFO1, getenv("USER"));
    sprintf(fifo2, "%s-%s", FIFO2, getenv("USER"));
    if (trace)
        msg_init_trace();
    if (exec)
        return 0;
    if (startup) {
        err = fifo_open(fifo1, O_WRONLY);
        assert(err != -1);
        ffds[1] = err;
        err = fifo_open(fifo2, O_RDONLY);
        assert(err != -1);
        ffds[0] = err;
        if (trace)
            trace_printf("cli: writing fifo\n");
        size = write(ffds[1], recv_buffer, 1);
        if (trace)
            trace_printf("cli: fifo write, size=%d\n", (int) size);
        assert(size == 1);
        if (trace)
            trace_printf("cli: fifo written\n");
        close(ffds[1]);
        return 0;
    }
    if (attach)
        ferr = file_init_attach(&argc, &argv, false, NULL);
    else
        ferr = file_init(&argc, &argv);
    TEST_CHK_FEOK(ferr);
    util_test_start(client);
    ferr = msg_mon_process_startup(true); // system messages
    util_check("msg_mon_process_startup", ferr);
    ferr = msg_mon_get_my_process_name(procname, BUFSIZ);
    util_check("msg_mon_get_my_process_name", ferr);
    ferr = msg_mon_get_process_info(procname, &nid, &pid);
    TEST_CHK_FEOK(ferr);

    if (trace)
        trace_printf("proc=%s, nid=%d, pid=%d\n", procname, nid, pid);
    dloop = (double) loop;
    for (inx = 0; inx < T_MAX; inx++)
        t_elapsed[inx] = 0.0;
    if (client) {
        printf("loop=%d, maxsp=%d\n", loop, maxsp);
        sargc = argc;
        assert(sargc < MAX_ARGS);
        for (inx2 = 0; inx2 < argc; inx2++) {
            if (strcmp(argv[inx2], "-client") == 0)
                sargv[inx2] = (char *) "-server";
            else
                sargv[inx2] = argv[inx2];
            if (strcmp(argv[inx2], "-attach") == 0)
                sargv[inx2] = (char *) "-server";
        }
        sargv[argc] = NULL;
        sprintf(sprog, "%s/%s", getenv("PWD"), argv[0]);
        time_start(T_TOTAL);
        for (inx = 0; inx < loop; inx += maxsp) {
            if (dif)
                snid = -1;
            else
                snid = nid;
            max = loop - inx;
            if (max > maxsp)
                max = maxsp;
            for (inx2 = 0; inx2 < max; inx2++)
                sname[inx2][0] = 0; // mon picks name
            if (trace)
                trace_printf("cli: newproc, inx=%d\n", inx);
            time_start(T_NEWPROC);
            for (inx2 = 0; inx2 < max; inx2++) {
                ferr = msg_mon_start_process(sprog,                  // prog
                                             sname[inx2],            // name
                                             sname[inx2],            // ret_name
                                             sargc,                  // argc
                                             sargv,                  // argv
                                             TPT_REF2(sphandle,inx2),// phandle
                                             false,                  // open
                                             &soid[inx2],            // oid
                                             MS_ProcessType_Generic, // type
                                             0,                      // priority
                                             false,                  // debug
                                             false,                  // backup
                                             &snid,                  // nid
                                             &spid,                  // pid
                                             NULL,                   // infile
                                             NULL);                  // outfile
                TEST_CHK_FEOK(ferr);
            }
            time_stop(T_NEWPROC);
            time_elapsed(T_NEWPROC);

            // wait here until processes are 'up'
            // so that open timing is correct
            inx3 = 0;
            for (inx2 = 0; inx2 < max; inx2++) {
                ferr = msg_mon_get_process_info_detail(sname[inx2], &info);
                TEST_CHK_FEOK(ferr);
                if (info.state != MS_Mon_State_Up) {
                    inx3++;
                    if (inx3 > MAX_RETRIES) {
                        printf("process %s did not enter 'UP' state\n", sname[inx2]);
                        assert(inx3 < MAX_RETRIES);
                    }
                    usleep(SLEEP_US);
                    inx2--;
                    continue;
                } else
                    inx3 = 0;
            }

            if (trace)
                trace_printf("cli: open, inx=%d\n", inx);
            time_start(T_OPEN);
            for (inx2 = 0; inx2 < max; inx2++) {
                if (trace)
                    trace_printf("cli: opening inx=%d, name=%s\n", inx, sname[inx2]);
                len = (short) strlen(sname[inx2]);
                ferr = BFILE_OPEN_(sname[inx2], len, &sfilenum[inx2],
                                   0, 0, 0,
                                   0, 0, 0, 0);
                if (trace)
                    trace_printf("cli: open, inx=%d, name=%s, ferr=%d\n",
                           inx, sname[inx2], ferr);
                TEST_CHK_FEOK(ferr);
            }
            time_stop(T_OPEN);
            time_elapsed(T_OPEN);

            if (trace)
                trace_printf("cli: procinfo, inx=%d\n", inx);
            time_start(T_PROCINFO);
            for (inx2 = 0; inx2 < max; inx2++) {
                ferr = msg_mon_get_process_info_detail(sname[inx2], &info);
                TEST_CHK_FEOK(ferr);
            }
            time_stop(T_PROCINFO);
            time_elapsed(T_PROCINFO);

            if (trace)
                trace_printf("cli: procinfo-type, inx=%d\n", inx);
            time_start(T_PROCINFO_TYPE);
            ferr = msg_mon_get_process_info_type(MS_ProcessType_Generic,
                                                 &count,
                                                 MAX_SRV,
                                                 infotype);
            TEST_CHK_FEOK(ferr);
            time_stop(T_PROCINFO_TYPE);
            time_elapsed(T_PROCINFO_TYPE);
            if (verbose) {
                for (inx2 = 0; inx2 < count; inx2++) {
                    infop = &infotype[inx2];
                    char s_em = infop->event_messages ? 'E' : '-';
                    char s_sm = infop->system_messages ? 'S' : '-';
                    char s_pr = infop->pending_replication ? 'R' : '-';
                    char s_pd = infop->pending_delete ? 'D' : '-';
                    char s_s  = infop->state == MS_Mon_State_Up ? 'A' : 'U';
                    char s_o  = infop->opened ? 'O' : '-';
                    char s_p  = infop->paired ? 'P' : infop->backup ? 'B' : '-';
                    printf("%3.3d,%8.8d %3.3d %d %c%c%c%c%c%c%c %-11s %-11s %-15s\n",
                           infop->nid,
                           infop->pid,
                           infop->priority,
                           infop->state,
                           s_em, s_sm, s_pr, s_pd, s_s, s_o, s_p,
                           infop->process_name,
                           infop->parent_name,
                           infop->program);
                }
            }

            if (trace)
                trace_printf("cli: close, inx=%d\n", inx);
            time_start(T_CLOSE);
            for (inx2 = 0; inx2 < max; inx2++) {
                ferr = BFILE_CLOSE_(sfilenum[inx2]);
                TEST_CHK_FEOK(ferr);
            }
            time_stop(T_CLOSE);
            time_elapsed(T_CLOSE);

            // re-open/close
            for (inx2 = 0; inx2 < max; inx2++) {
                if (trace)
                    trace_printf("cli: re-opening inx=%d, name=%s\n",
                           inx, sname[inx2]);
                len = (short) strlen(sname[inx2]);
                ferr = BFILE_OPEN_(sname[inx2], len, &sfilenum[inx2],
                                   0, 0, 0,
                                   0, 0, 0, 0);
                TEST_CHK_FEOK(ferr);
            }
            if (trace)
                trace_printf("cli: re-close, inx=%d\n", inx);
            for (inx2 = 0; inx2 < max; inx2++) {
                ferr = BFILE_CLOSE_(sfilenum[inx2]);
                TEST_CHK_FEOK(ferr);
            }

            if (trace)
                trace_printf("cli: newproc-forkexec, inx=%d\n", inx);
            sargc = 2;
            sargv[0] = argv[0];
            sargv[1] = (char *) "-exec";
            if (trace)
                sargv[sargc++] = (char *) "-trace";
            sargv[sargc] = NULL;
            time_start(T_FORKEXEC);
            for (inx2 = 0; inx2 < max; inx2++) {
                pid = fork();
                assert(pid >= 0);
                if (pid == 0) {
                    // child
                    err = execv(sprog, sargv);
                    assert(err == 0);
                }
            }
            time_stop(T_FORKEXEC);
            time_elapsed(T_FORKEXEC);

            if (trace)
                trace_printf("cli: newproc-forkexec-su, inx=%d\n", inx);
            sargc = 2;
            sargv[0] = argv[0];
            sargv[1] = (char *) "-startup";
            if (trace)
                sargv[sargc++] = (char *) "-trace";
            sargv[sargc] = NULL;
            time_start(T_FORKEXEC_SU);
            for (inx2 = 0; inx2 < max; inx2++) {
                fifo_create(fifo1, fifo2);
                pid = fork();
                assert(pid >= 0);
                if (pid > 0) {
                    // parent
                    err = fifo_open(fifo1, O_RDONLY);
                    assert(err != -1);
                    ffds[0] = err;
                    err = fifo_open(fifo2, O_WRONLY);
                    assert(err != -1);
                    ffds[1] = err;
                    if (trace)
                        trace_printf("cli: reading fifo, inx=%d\n", inx2);
                    size = ::read(ffds[0], recv_buffer, 1);
                    if (trace)
                        trace_printf("cli: fifo read, size=%d\n", (int) size);
                    assert(size == 1);
                    if (trace)
                        trace_printf("cli: fifo read, inx=%d\n", inx2);
                    ::read(ffds[0], recv_buffer, 1);
                    err = fifo_close(ffds[0]);
                    assert(err == 0);
                    err = fifo_close(ffds[1]);
                    assert(err == 0);
                    fifo_destroy(fifo1, fifo1);
                } else {
                    // child
                    err = execv(sprog, sargv);
                    assert(err == 0);
                }
            }
            fifo_destroy(fifo2, fifo2);
            time_stop(T_FORKEXEC_SU);
            time_elapsed(T_FORKEXEC_SU);
        }
    } else {
        sys_msg_count = 0;
        time_start(T_TOTAL);
        ferr = BFILE_OPEN_((char *) "$RECEIVE", 8, &filenumr,
                           0, 0, 0,
                           1, 0); // sys msgs
        TEST_CHK_FEOK(ferr);
        for (inx = 0; !fin; inx++) {
            if (trace)
                trace_printf("srv: readupdate, inx=%d\n", inx);
            cc = BREADUPDATEX(filenumr,
                              recv_buffer,
                              4,
                              &count_read,
                              0);
            sys_msg = _xstatus_ne(cc);
            if (trace && sys_msg)
                trace_printf("srv: rcvd sys msg=%d\n",
                             sys_msgp->u_z_msg.z_msgnumber[0]);
            if (sys_msg) {
                sys_msg_count++;
                inx--;
            }
            lerr2 = BFILE_GETINFO_(filenumr, &lerr);
            TEST_CHK_FEIGNORE(lerr2);
            if (trace)
                trace_printf("srv: reply, inx=%d\n", inx);
            cc = BREPLYX(recv_buffer,
                         (unsigned short) 0,
                         &count_written,
                         0,
                         XZFIL_ERR_OK);
            TEST_CHK_CCEQ(cc);
            if (sys_msg_count >= 4)
                fin = true;
        }
    }
    time_stop(T_TOTAL);
    time_elapsed(T_TOTAL);

    if (client) {
        dsec = time_sec(T_TOTAL);
        dms = dsec * 1000.0;
        printf("elapsed=%f\n", dms);
        printf("open/close/newprocess/processinfo/forkexec=%d\n", loop);
        dsec = time_sec(T_OPEN);
        dms = dsec * 1000.0;
        printf("open            : total-time=%f ms, time/loop=%f ms, ops/sec=%f\n",
               dms, dms / dloop, dloop / dsec);
        dsec = time_sec(T_CLOSE);
        dms = dsec * 1000.0;
        printf("close           : total-time=%f ms, time/loop=%f ms, ops/sec=%f\n",
               dms, dms / dloop, dloop / dsec);
        dsec = time_sec(T_PROCINFO);
        dms = dsec * 1000.0;
        printf("procinfo        : total-time=%f ms, time/loop=%f ms, ops/sec=%f\n",
               dms, dms / dloop, dloop / dsec);
        dsec = time_sec(T_PROCINFO_TYPE);
        dms = dsec * 1000.0;
        printf("procinfo-type   : total-time=%f ms, time/loop=%f ms, ops/sec=%f\n",
               dms, dms / dloop, dloop / dsec);
        dsec = time_sec(T_NEWPROC);
        dms = dsec * 1000.0;
        printf("newproc         : total-time=%f ms, time/loop=%f ms, ops/sec=%f\n",
               dms, dms / dloop, dloop / dsec);
        dsec = time_sec(T_FORKEXEC);
        dms = dsec * 1000.0;
        printf("forkexec        : total-time=%f ms, time/loop=%f ms, ops/sec=%f\n",
               dms, dms / dloop, dloop / dsec);
        dsec = time_sec(T_FORKEXEC_SU);
        dms = dsec * 1000.0;
        printf("forkexec-startup: total-time=%f ms, time/loop=%f ms, ops/sec=%f\n",
               dms, dms / dloop, dloop / dsec);
    }
    ferr = msg_mon_process_shutdown();
    TEST_CHK_FEOK(ferr);
    util_test_finish(client);
    return 0;
}
コード例 #12
0
ファイル: fio.c プロジェクト: Paul-Reed/daemon
int main(int ac, char **av)
{
	const char * const fifoname = "./fio.fifo";
	const char * const filename = "./fio.file";
	const mode_t mode = S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH;
	FILE *file;
	char line[BUFSIZ];
	const int lock = 1;
	int errors = 0;
	int fd, wfd;

	if (ac == 2 && !strcmp(av[1], "help"))
	{
		printf("usage: %s\n", *av);
		return EXIT_SUCCESS;
	}

	printf("Testing: %s\n", "fio");

	umask(0);

	if ((fd = fifo_open(fifoname, mode, lock, &wfd)) == -1)
	{
		++errors, printf("Test1: fifo_open(\"%s\", %d, %d) failed (%s)\n", fifoname, (int)mode, lock, strerror(errno));
#ifndef HAVE_FCNTL_THAT_CAN_LOCK_FIFOS
		printf("\n      Can your system lock fifos?\n\n");
#endif
	}
	else
	{
		if ((fcntl_lock(fd, F_SETLK, F_WRLCK, SEEK_SET, 0, 0)) != -1)
			++errors, printf("Test2: fcntl_lock(wrlock) failed\n");

		/* Should really test that the following non-blocking changes do occur */

		if (nonblock_on(fd) == -1)
			++errors, printf("Test3: nonblock_on() failed (%s)\n", strerror(errno));

		if (nonblock_off(fd) == -1)
			++errors, printf("Test4: nonblock_off() failed (%s)\n", strerror(errno));

		if (fcntl_set_flag(fd, O_NONBLOCK) == -1)
			++errors, printf("Test5: fcntl_set_flag() failed (%s)\n", strerror(errno));

		if (fcntl_clear_flag(fd, O_NONBLOCK) == -1)
			++errors, printf("Test6: fcntl_clear_flag() failed (%s)\n", strerror(errno));

		close(fd);
		close(wfd);
		unlink(fifoname);
	}

#define CHECK_FGETLINE(i, size, expected) \
	if ((expected) && !fgetline(line, (size), file)) \
		++errors, printf("Test%d: fgetline() failed\n", (i)); \
	else if ((expected) && strcmp(line, ((expected) ? (expected) : ""))) \
		++errors, printf("Test%d: fgetline() read \"%s\", not \"%s\"\n", (i), line, (expected ? expected : "(null)"));

#define TEST_FGETLINE(i, buf, size, contents, line1, line2, line3) \
	if (!(file = fopen(filename, "wb"))) \
		++errors, printf("Test%d: failed to run test: failed to create test file\n", (i)); \
	else \
	{ \
		if (fwrite((contents), 1, strlen(contents), file) != strlen(contents)) \
			++errors, printf("Test%d: failed to run test: failed to write to test file\n", (i)); \
		else \
		{ \
			fclose(file); \
			if (!(file = fopen(filename, "r"))) \
				++errors, printf("Test%d: failed to run test: failed to open test file for reading\n", (i)); \
			else \
			{ \
				CHECK_FGETLINE((i), (size), (line1)) \
				CHECK_FGETLINE((i), (size), (line2)) \
				CHECK_FGETLINE((i), (size), (line3)) \
				if (fgetline(buf, BUFSIZ, file)) \
					++errors, printf("Test%d: fgetline() failed to return NULL at end of file\n", (i)); \
			} \
		} \
		fclose(file); \
		unlink(filename); \
	}

	TEST_FGETLINE(7, line, BUFSIZ, "abc\ndef\r\nghi\r", "abc\n", "def\n", "ghi\n")
	TEST_FGETLINE(8, line, BUFSIZ, "abc\rdef\nghi\r\n", "abc\n", "def\n", "ghi\n")
	TEST_FGETLINE(9, line, BUFSIZ, "abc\r\ndef\rghi\n", "abc\n", "def\n", "ghi\n")
	TEST_FGETLINE(10, line, BUFSIZ, "abc\ndef\rghi", "abc\n", "def\n", "ghi")
	TEST_FGETLINE(11, line, BUFSIZ, "", (char *)NULL, (char *)NULL, (char *)NULL)
	TEST_FGETLINE(12, line, 5, "abc", "abc", (char *)NULL, (char *)NULL)
	TEST_FGETLINE(13, line, 5, "abc\n", "abc\n", (char *)NULL, (char *)NULL)
	TEST_FGETLINE(14, line, 5, "abc\r\n", "abc\n", (char *)NULL, (char *)NULL)
	TEST_FGETLINE(15, line, 5, "abc\r", "abc\n", (char *)NULL, (char *)NULL)
	TEST_FGETLINE(16, line, 3, "abc\r", "ab", "c\n", (char *)NULL)
	TEST_FGETLINE(17, NULL, 0, "abc\r", (char *)NULL, (char *)NULL, (char *)NULL)

	/* Test read_timeout() and write_timeout() */

	if ((fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_NONBLOCK, S_IRUSR | S_IWUSR)) == -1)
		++errors, printf("Test19: failed to create %s (%s)\n", filename, strerror(errno));
	else
	{
		char buf[12] = "0123456789\n";

		if (write_timeout(fd, 1, 0) == -1)
			++errors, printf("Test18: write_timeout(fd, 1, 0) failed (%s)\n", strerror(errno));
		else if (write(fd, buf, 11) != 11)
			++errors, printf("Test18: write(fd, \"0123456789\\n\", 11) failed (%s)\n", strerror(errno));
		else
		{
			close(fd);

			if ((fd = open(filename, O_RDONLY | O_NONBLOCK)) == -1)
				++errors, printf("Test19: failed to open %s for reading (%s)\n", filename, strerror(errno));
			else if (read_timeout(fd, 1, 0) == -1)
				++errors, printf("Test19: read_timeout(fd, 1, 0) failed (%s)\n", strerror(errno));
			else if (read(fd, buf, 11) != 11)
				++errors, printf("Test19: read(fd) failed (%s)\n", strerror(errno));
		}

		close(fd);
	}

	unlink(filename);

	/* Test error handling */

#define TEST_ERR(i, func) \
	if ((func) != -1) \
		++errors, printf("Test%d: %s failed to return -1\n", (i), (#func)); \
	else if (errno != EINVAL) \
		++errors, printf("Test%d: %s failed (errno = %s, not %s)\n", (i), (#func), strerror(errno), strerror(EINVAL));

	TEST_ERR(20, read_timeout(-1, 0, 0))
	TEST_ERR(21, read_timeout(0, -1, 0))
	TEST_ERR(22, read_timeout(0, 0, -1))
	TEST_ERR(23, write_timeout(-1, 0, 0))
	TEST_ERR(24, write_timeout(0, -1, 0))
	TEST_ERR(25, write_timeout(0, 0, -1))
	TEST_ERR(26, rw_timeout(-1, 0, 0))
	TEST_ERR(27, rw_timeout(0, -1, 0))
	TEST_ERR(28, rw_timeout(0, 0, -1))
	TEST_ERR(29, nap(-1, 0))
	TEST_ERR(30, nap(0, -1))

	if (errors)
		printf("%d/30 tests failed\n", errors);
	else
		printf("All tests passed\n");

#ifndef HAVE_FCNTL_THAT_CAN_LOCK_FIFOS
	printf("\n");
	printf("    Note: Some systems (e.g. FreeBSD) can't lock fifos so fifo_open()\n");
	printf("    can't guarantee a unique reader.\n");
#endif

	return (errors == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
コード例 #13
0
ファイル: initctl.c プロジェクト: rrogers96/finit
/* Standard reboot/shutdown utilities talk to init using /dev/initctl.
 * We should check if the fifo was recreated and reopen it.
 */
static void parse(void *UNUSED(arg), int fd, int UNUSED(events))
{
	struct init_request rq;

	while (1) {
		ssize_t len = read(fd, &rq, sizeof(rq));

		if (len <= 0) {
			if (-1 == len) {
				if (EINTR == errno)
					continue;

				if (EAGAIN == errno)
					break;

				_e("Failed reading initctl request, error %d: %s", errno, strerror(errno));
			}

			_d("Nothing to do, bailing out.");
			break;
		}

		if (rq.magic != INIT_MAGIC || len != sizeof(rq)) {
			_e("Invalid initctl request.");
			break;
		}

		switch (rq.cmd) {
		case INIT_CMD_RUNLVL:
			switch (rq.runlevel) {
			case '0':
				_d("Halting system (SIGUSR2)");
				do_shutdown(SIGUSR2);
				break;

			case 's':
			case 'S':
				_d("Cannot enter bootstrap after boot ...");
				rq.runlevel = '1';
				/* Fall through to regular processing */

			case '1'...'5':
			case '7'...'9':
				_d("Setting new runlevel %c", rq.runlevel);
				service_runlevel(rq.runlevel - '0');
				break;

			case '6':
				_d("Rebooting system (SIGUSR1)");
				do_shutdown(SIGUSR1);
				break;

			default:
				_d("Unsupported runlevel: %d", rq.runlevel);
				break;
			}
			break;

		case INIT_CMD_RELOAD:
			service_reload_dynamic();
			break;

		default:
			_d("Unsupported cmd: %d", rq.cmd);
			break;
		}
	}

	close(fd);
	fifo_open();
}
コード例 #14
0
ファイル: fifo_test.c プロジェクト: vaesumed/Muse-BBB
int main(int argc, char ** argv){
	unsigned int i ;
	long start_time, end_time ;
	double diff_time ;
	struct timespec cpu_time ;
	if(fifo_open(0) < 0){
		printf("cannot open fifo !\n"); 
		return -1 ;
	}
	fifo_reset(0);
	unsigned int size =  fifo_getSize(0) ;
	unsigned int nb_avail = fifo_getNbAvailable(0);
	unsigned int nb_free = fifo_getNbFree(0);
	printf("fifo 0 of size %d contains %d tokens , %d free slots \n", size, nb_avail, nb_free);
	while(1){
		fifo_reset(0);
		fifo_read(0, buffer, 4096);
		printf("done \n");
	}
	//fifo_reset(0) ;
	//return 0 ;
	fifo_write(0, buffer, 640);
	sleep(3);
	//fifo_read(0, buffer, 1024);
	size =  fifo_getSize(0) ;
        nb_avail = fifo_getNbAvailable(0);
        nb_free = fifo_getNbFree(0);
	printf("fifo 0 of size %d contains %d tokens , %d free slots \n", size, nb_avail, nb_free);
	return 0 ;
	clock_gettime(CLOCK_REALTIME, &cpu_time);
	start_time = cpu_time.tv_nsec ;
	fifo_write(0, buffer, 4096) ;
	clock_gettime(CLOCK_REALTIME, &cpu_time);
	end_time = cpu_time.tv_nsec ;
	diff_time = end_time - start_time ;
	diff_time = diff_time/1000000000.0 ;
	printf("transffered %d bytes in %f s : %f B/s \n", 4096, diff_time, 4096/diff_time);
	printf("read and write done \n");
	//printf("fifo 1 is %d large and contains %d tokens \n", fifo_getSize(1), fifo_getNbAvailable(1));
	/*while(1){
		fifo_reset(1);
		fifo_read(1, buffer, 32*6);
		for(i = 0 ; i < 5 ; i ++){
			unsigned int posx0, posy0, posx1, posy1;
			posy0 = buffer[i*(6)];
			posy0 += (buffer[(i*(6))+1] & 0x03 << 8);
			posx0 = (buffer[(i*(6))+1] & 0xFC >> 2);
			posx0 += (buffer[(i*(6))+2] & 0x03 << 8);

			posy1 = (buffer[i*(6)+2] & 0xFC >> 2);
			posy1 += (buffer[(i*(6))+3] & 0x03 << 8);
			posx1 = (buffer[(i*(6))+3] & 0xFC >> 2);
			posx1 += (buffer[(i*(6))+4] & 0x03 << 8);


			printf("x[%d] = %d, y[%d] = %d \n", i, (posx0 + posx1)/2, i, (posy0 + posy1)/2);
		}
		sleep(1);	
	}*/ //blob_tracking test ...
	fifo_close(0);
}
コード例 #15
0
ファイル: wifibc-tx.c プロジェクト: OpenGelo/multigcs
int main(int argc, char *argv[]) {
	char szErrbuf[PCAP_ERRBUF_SIZE];
	int i;
	pcap_t *ppcap = NULL;
	char fBrokenSocket = 0;
	int pcnt = 0;
	time_t start_time;
	uint8_t packet_transmit_buffer[MAX_PACKET_LENGTH];
	size_t packet_header_length = 0;
	fd_set fifo_set;
	int max_fifo_fd = -1;
	fifo_t fifo[MAX_FIFOS];
	int param_transmission_count = 1;
	int param_data_packets_per_block = 8;
	int param_fec_packets_per_block = 4;
	int param_packet_length = MAX_USER_PACKET_LENGTH;
	int param_port = 0;
	int param_min_packet_length = 0;
	int param_fifo_count = 1;
	strcpy(param_serial_port, "/dev/ttyUSB0");
	running = 1;
	printf("Raw data transmitter (c) 2015 befinitiv  GPL2\n");
	while (1) {
		int nOptionIndex;
		static const struct option optiona[] = {
			{ "help", no_argument, &flagHelp, 1 },
			{ 0, 0, 0, 0 }
		};
		int c = getopt_long(argc, argv, "r:hf:p:b:m:s:x:P:B:", optiona, &nOptionIndex);
		if (c == -1) {
			break;
		}
		switch (c) {
			case 0: // long option
				break;
			case 'h': // help
				usage();
			case 'r': // retransmissions
				param_fec_packets_per_block = atoi(optarg);
				break;
			case 'f': // MTU
				param_packet_length = atoi(optarg);
				break;
			case 'p': //port
				param_port = atoi(optarg);
				break;
			case 'b': //retransmission block size
				param_data_packets_per_block = atoi(optarg);
				break;
			case 'm'://minimum packet length
				param_min_packet_length = atoi(optarg);
				break;
			case 's': //how many streams (fifos) do we have in parallel
				param_fifo_count = atoi(optarg);
				break;
			case 'x': //how often is a block transmitted
				param_transmission_count = atoi(optarg);
				break;
			case 'P': //Serial-Port
				strcpy(param_serial_port, optarg);
				break;
			case 'B': //Serial-Baud
				param_serial_baud = atoi(optarg);
				break;
			default:
				printf("unknown switch %c\n", c);
				usage();
				break;
		}
	}
	if (optind >= argc) {
		usage();
	}
	mavlink_init(0, param_serial_port, param_serial_baud);
#ifdef SDL2
	wifibc_thread_telemetry = SDL_CreateThread(wifibc_update_telemetry, NULL, NULL);
#else
	wifibc_thread_telemetry = SDL_CreateThread(wifibc_update_telemetry, NULL);
#endif
	if (param_packet_length > MAX_USER_PACKET_LENGTH) {
		printf("Packet length is limited to %d bytes (you requested %d bytes)\n", MAX_USER_PACKET_LENGTH, param_packet_length);
		return (1);
	}
	if (param_min_packet_length > param_packet_length) {
		printf("Your minimum packet length is higher that your maximum packet length (%d > %d)\n", param_min_packet_length, param_packet_length);
		return (1);
	}
	if (param_fifo_count > MAX_FIFOS) {
		printf("The maximum number of streams (FIFOS) is %d (you requested %d)\n", MAX_FIFOS, param_fifo_count);
		return (1);
	}
	if (param_data_packets_per_block > MAX_DATA_OR_FEC_PACKETS_PER_BLOCK || param_fec_packets_per_block > MAX_DATA_OR_FEC_PACKETS_PER_BLOCK) {
		printf("Data and FEC packets per block are limited to %d (you requested %d data, %d FEC)\n", MAX_DATA_OR_FEC_PACKETS_PER_BLOCK,
			   param_data_packets_per_block, param_fec_packets_per_block);
		return (1);
	}
	packet_header_length = packet_header_init(packet_transmit_buffer);
	fifo_init(fifo, param_fifo_count, param_data_packets_per_block);
	fifo_open(fifo, param_fifo_count);
	fifo_create_select_set(fifo, param_fifo_count, &fifo_set, &max_fifo_fd);
	//initialize forward error correction
	fec_init();
	// open the interface in pcap
	szErrbuf[0] = '\0';
	ppcap = pcap_open_live(argv[optind], 800, 1, 20, szErrbuf);
	if (ppcap == NULL) {
		printf("Unable to open interface %s in pcap: %s\n",
			   argv[optind], szErrbuf);
		return (1);
	}
	pcap_setnonblock(ppcap, 1, szErrbuf);
	start_time = time(NULL);
	while (!fBrokenSocket) {
		fd_set rdfs;
		int ret;
		rdfs = fifo_set;
		//wait for new data on the fifos
		ret = select(max_fifo_fd + 1, &rdfs, NULL, NULL, NULL);
		if (ret < 0) {
			perror("select");
			return (1);
		}
		//cycle through all fifos and look for new data
		for (i = 0; i < param_fifo_count && ret; ++i) {
			if (!FD_ISSET(fifo[i].fd, &rdfs)) {
				continue;
			}
			ret--;
			packet_buffer_t *pb = fifo[i].pbl + fifo[i].curr_pb;
			//if the buffer is fresh we add a payload header
			if (pb->len == 0) {
				pb->len += sizeof(payload_header_t); //make space for a length field (will be filled later)
			}
			//read the data
			int inl = read(fifo[i].fd, pb->data + pb->len, param_packet_length - pb->len - sizeof(ModelDataMinimal));
			if (inl < 0 || inl > param_packet_length - pb->len - sizeof(ModelDataMinimal)) {
				perror("reading stdin");
				return 1;
			}
			if (inl == 0) {
				//EOF
				printf("Warning: Lost connection to fifo %d. Please make sure that a data source is connected\n", i);
				usleep(1e5);
				continue;
			}
			pb->len += inl;
			// add telemtry-data
			ModelDataMinimal.p_lat = ModelData[0].p_lat;
			ModelDataMinimal.p_long = ModelData[0].p_long;
			ModelDataMinimal.p_alt = ModelData[0].p_alt;
			ModelDataMinimal.pitch = ModelData[0].pitch;
			ModelDataMinimal.roll = ModelData[0].roll;
			ModelDataMinimal.yaw = ModelData[0].yaw;
			ModelDataMinimal.speed = ModelData[0].speed;
			ModelDataMinimal.voltage = ModelData[0].voltage;
			ModelDataMinimal.ampere = ModelData[0].ampere;
			ModelDataMinimal.gpsfix = ModelData[0].gpsfix;
			ModelDataMinimal.numSat = ModelData[0].numSat;
			memcpy(pb->data + pb->len + param_packet_length, &ModelDataMinimal, sizeof(ModelDataMinimal));
			pb->len += sizeof(ModelDataMinimal);
			//check if this packet is finished
			if (pb->len >= param_min_packet_length) {
				payload_header_t *ph = (payload_header_t *)pb->data;
				ph->data_length = pb->len - sizeof(
									  payload_header_t); //write the length into the packet. this is needed since with fec we cannot use the wifi packet lentgh anymore. We could also set the user payload to a fixed size but this would introduce additional latency since tx would need to wait until that amount of data has been received
				pcnt++;
				//check if this block is finished
				if (fifo[i].curr_pb == param_data_packets_per_block - 1) {
					pb_transmit_block(fifo[i].pbl, ppcap, &(fifo[i].seq_nr), i + param_port, param_packet_length, packet_transmit_buffer, packet_header_length,
									  param_data_packets_per_block, param_fec_packets_per_block, param_transmission_count);
					fifo[i].curr_pb = 0;
				} else {
					fifo[i].curr_pb++;
				}
			}
		}
		if (pcnt % 64 == 0) {
			printf("%d data packets sent (interface rate: %.3f)\n", pcnt, 1.0 * pcnt / param_data_packets_per_block * (param_data_packets_per_block + param_fec_packets_per_block) / (time(NULL) - start_time));
		}
	}
	running = 0;
	SDL_WaitThread(wifibc_thread_telemetry, NULL);
	mavlink_exit(0);
	printf("Broken socket\n");
	return (0);
}
コード例 #16
0
int main(int argc, char ** argv){
	long start_time, end_time ;
	double diff_time ;
	struct timespec cpu_time ;
	unsigned short vsync1, vsync2 ;
	FILE * rgb_fd, * yuv_fd ;
	int i,j, res, inc = 0;
	unsigned int nbFrames = 1 ;
	unsigned int pos = 0 ;
	unsigned char * image_buffer, * start_buffer, * end_ptr; //yuv frame buffer
	unsigned char * rgb_buffer ;
	unsigned short fifo_state, fifo_data ;
	float y, u, v ;
	float r, g, b ;
	if(argc > 1){
		nbFrames = atoi(argv[1]);
	}
	if(fifo_open(1) < 0 || image_buffer == 0){
                        printf("Error opening fifo 0 \n");
                        return -1 ;     
        }
	image_buffer = (unsigned char *) malloc(IMAGE_WIDTH*IMAGE_HEIGHT*3);
	for(inc = 0 ; inc < nbFrames ; ){
		sprintf(yuv_file_name, "./grabbed_frame%04d.jpg", inc);
		yuv_fd  = fopen(yuv_file_name, "w");
		if(yuv_fd == NULL){
			perror("Error opening output file");
			exit(EXIT_FAILURE);
		}
		//fifo_reset(1);
		clock_gettime(CLOCK_REALTIME, &cpu_time);
		start_time = cpu_time.tv_nsec ;
		fifo_reset(1);
		fifo_read(1, image_buffer, IMAGE_WIDTH*IMAGE_HEIGHT*3);
		clock_gettime(CLOCK_REALTIME, &cpu_time);
		end_time = cpu_time.tv_nsec ;
		diff_time = end_time - start_time ;
		diff_time = diff_time/1000000000 ;
		printf("transffered %d bytes in %f s : %f B/s \n", (IMAGE_WIDTH * IMAGE_HEIGHT*3), diff_time, (IMAGE_WIDTH * IMAGE_HEIGHT*3)/diff_time);
		start_buffer = image_buffer ;
		end_ptr = &image_buffer[IMAGE_WIDTH*IMAGE_HEIGHT*3];
		vsync1 = *((unsigned short *) start_buffer) ;
		vsync2 = *((unsigned short *) &start_buffer[(IMAGE_WIDTH*IMAGE_HEIGHT)+2]) ;
		while(vsync1 != 0x55AA && vsync2 != 0x55AA && start_buffer < end_ptr){
			start_buffer+=2 ;
			vsync1 = *((unsigned short *) start_buffer) ;
			vsync2 = *((unsigned short *) &start_buffer[(IMAGE_WIDTH*IMAGE_HEIGHT)+2]) ;
			//printf("vsync2 : %x \n", vsync2);
		}
		if(vsync1 == 0x55AA && vsync2 == 0x55AA){
			inc ++ ;
			printf("frame found !\n");
		}else{
                	//fclose(yuv_fd);
			//continue ;
			start_buffer = image_buffer ;
			inc ++ ;
		}
		start_buffer += 2 ;
		printf("frame captures \n");
		write_jpegfile(start_buffer, IMAGE_WIDTH, IMAGE_HEIGHT, 1, yuv_fd, 100);
		fclose(yuv_fd);
	}
	fifo_close(1);
	return 0 ;
}
コード例 #17
0
ファイル: witplay.c プロジェクト: maxwit/witplayer
int main(int argc, char *argv[])
{
	int ret;
	const char *url;
	struct sound_file_info *file;
	struct decode *dec;
	struct fifo *fifo;
	pthread_t tid;
	struct load_thread_arg arg;
	u8 *lrc;
	u8 *icon;
	size_t lrc_size;
	size_t icon_size;
	u8 mp3_buff[MP3_BUFF_SIZE];
	u8 raw_buff[RAW_BUFF_SIZE];
	int mp3_size, raw_size;
	struct mp3_param mp3_pm;
	struct audio_output *out;
	struct window_info *win_info;

	if (argc < 2) {
		fprintf(stderr, "Usage: %s PATH\n", argv[0]);
		return -EINVAL;
	}

	url = argv[1];

	file = sound_file_open(url);
	if (NULL == file) {
		fprintf(stderr, "Fail to open sound file \"%s\"!\n", url);
		return -ENODEV;
	}

	fifo = fifo_open();
	if (NULL == fifo) {
		goto L1;
		ret = -ENOMEM;
	}

	ret = parse_mp3_tag(file, &lrc, &lrc_size, &icon, &icon_size);
	if (ret < 0) {
		DPRINT("\n");
		goto L2;
	}

	DPRINT("mp3_start = %lu, mp3_end = %lu, "
			"lrc = %p, lrc_size = %lu, icon = %p, icon_size = %lu\n",
			file->mp3_data_start, file->mp3_data_end,
			lrc, lrc_size, icon, icon_size);

	arg.fifo = fifo;
	arg.file = file;
	ret = pthread_create(&tid, NULL, load_mp3_data_to_fifo, &arg);
	if (ret < 0) {
		DPRINT("\n");
		goto L2;
	}

	dec = decode_open(MPAUDEC); // fixme!
	if (NULL == dec) {
		ret = -ENODEV;
		goto L2;
	}

	while (fifo->used < fifo->size / 3) usleep(1000);
	mp3_size = fifo_read(fifo, mp3_buff, sizeof(mp3_buff));

	get_mp3_param(dec, mp3_buff, mp3_size, &mp3_pm);

	win_info = window_init();
	win_info->icon = icon;
	win_info->icon_size = icon_size;
	win_info->lrc = lrc;
	win_info->lrc_size = lrc_size;
	win_info->total.tv_sec = (file->mp3_data_end - file->mp3_data_start) * 8 / mp3_pm.bit_rate;
	win_info->total.tv_usec = (file->mp3_data_end - file->mp3_data_start) * 8 * 1000000 / mp3_pm.bit_rate % 1000000;
	win_info->param = &mp3_pm;

	DPRINT("rate = %d, channels = %d, bps = %d, bitrate = %d\n",
			mp3_pm.rate, mp3_pm.channels, mp3_pm.bits_per_sample, mp3_pm.bit_rate);

	out = open_audio(AUDIO_ALSA, &mp3_pm);
	if (NULL == out) {
		ret = -ENODEV;
		goto L3;
	}

	while (1) {
		if (file->mp3_data_end == file->offset && mp3_size == 0)
			break;

		if (mp3_size > 0) {
			ret = decode(dec, raw_buff, &raw_size, mp3_buff, mp3_size);
			mp3_size -= ret;
			memmove(mp3_buff, mp3_buff + ret, mp3_size);
		}

		play_frames(out, raw_buff, raw_size, &mp3_pm);

		ret = fifo_read(fifo, mp3_buff + mp3_size, sizeof(mp3_buff) - mp3_size);

		mp3_size += ret;
	}

	close_audio(out);
	window_destroy();
L3:
	decode_close(dec);
L2:
	fifo_close(fifo);
L1:
	sound_file_close(file);

	return ret;
}