コード例 #1
0
ファイル: ej4.c プロジェクト: fernansd/SO
int main (int argc, char **argv) {
	pid_t pid_gedit, pid_calc;
	pid_calc =	fork();
	int status_calc, status_gedit;

	switch (pid_calc) {
		case -1:
			printf("Error forking Calc\n");
			break;
		case 0:
			llamaCalculadora();
			break;
		default:
			printf("calc\n");
			waitpid(pid_calc,&status_calc, 0);
			status_handler(&status_calc, pid_calc);	
			pid_gedit = fork();

	}

	switch(pid_gedit) {
		case -1:
			printf("Error forking Gedit\n");
			break;
		case 0:
			llamaGedit(argv,argc);
			break;
		default:
			printf("gedit\n");
			waitpid(pid_gedit,&status_gedit,0);
			status_handler(&status_gedit, pid_gedit);
	}

return 0;
}
コード例 #2
0
ファイル: xl2tpd.c プロジェクト: greendev5/xl2tpd
void process_signal(void)
{
    if (sigterm_received) { sigterm_received = 0; death_handler(SIGTERM); }
    if (sigint_received) { sigint_received = 0; death_handler(SIGINT); }
    if (sigchld_received) { sigchld_received = 0; child_handler(SIGCHLD); }
    if (sigusr1_received) { sigusr1_received = 0; status_handler(SIGUSR1); }
    if (sighup_received) { sighup_received = 0; null_handler(SIGHUP); }
}
コード例 #3
0
ファイル: job_control.c プロジェクト: sanbeg/ripperx
/* called after all jobs are finshed. Files are cleaned up and renamed */
void job_finisher(_main_data *main_data)
{
    int i;
    static char status_message[(MAX_FILE_PATH_LENGTH + MAX_FILE_NAME_LENGTH) * MAX_NUM_TRACK ];
    static char buffer[(MAX_FILE_PATH_LENGTH + MAX_FILE_NAME_LENGTH) * MAX_NUM_TRACK ];
    static char *wav_file, *enc_file;
    int madewavs = FALSE;
    int mademp3s = FALSE;
    int tracksdone = 0;
    char *s_track_num;
    char *artist;
    ID3Tag *myTag;

    FILE *fp_playlist = NULL;
    char playlist_filespec[ MAX_FILE_PATH_LENGTH + MAX_FILE_NAME_LENGTH ];

    /* Allocate space dynamically.  This is overkill, but certainly won't be a problem. */
    s_track_num = (char *) malloc((main_data->num_tracks + 2) * sizeof(char));
    buffer[0] = 0;

    /* Clean up */
    for(i = 0; i < main_data->num_tracks; i++)
    {
        create_file_names_for_track(main_data, i, &wav_file, &enc_file);

        if(main_data->track[ i ].wav_exist == FALSE)
        {
            unlink(wav_file);
        }
        else if(main_data->track[ i ].make_wav == TRUE)
        {
            madewavs = TRUE;
            sprintf(&buffer[strlen(buffer)], "%d: %s\n", ++tracksdone, file_name_without_path(wav_file));
        }

        main_data->track[ i ].make_wav = FALSE;

        if(main_data->track[ i ].mp3_exist == TRUE && main_data->track[ i ].make_mp3 == TRUE)
        {
            mademp3s = TRUE;

            /* add ID3 tag if requested */
            if(config.cddb_config.create_id3 == TRUE)
            {
                if(!(artist = main_data->track[ i ].artist))
                {
                    artist = main_data->disc_artist;
                }

                // TODO:  fix this to use something like
                //		if (main_data->encoding_type == OGG) {

                if(!strcmp(config.encoder.encoder, "oggenc"))
                {
                    /* set VORBIS tags using vorbistag - added DATE tag - R. Turnbull 1-2-2010 */
                    vorbistag(enc_file,
                              artist,
                              main_data->disc_title,
                              main_data->disc_year,
                              main_data->track[i].title,
                              id3_find_cddb_category(main_data->disc_category),
                              i + 1);
                }
                else if(!strcmp(config.encoder.encoder, "flac"))
                {
                    /* set FLAC tags using metaflac R. Turnbull 1-2-2010 */
                    flactag(enc_file,
                            artist,
                            main_data->disc_title,
                            main_data->disc_year,
                            main_data->track[i].title,
                            id3_find_cddb_category(main_data->disc_category),
                            i + 1);
                }
                else if(!strcmp(config.encoder.encoder, "mppenc"))
                {
                    /* do nothing for for musepack right now -
                        originally supported id3 now wants apev2 tags */
                }
                else
                {
                    /* assume MP3 tag is desired */
                    sprintf(s_track_num,"%d",(i+1));

                    myTag=ID3Tag_New();
                    ID3Tag_Link(myTag,enc_file);

                    set_TagField(myTag, main_data->track[ i ].title, ID3FID_TITLE);
                    set_TagField(myTag, artist, ID3FID_LEADARTIST);
                    set_TagField(myTag, main_data->disc_title, ID3FID_ALBUM);
                    set_TagField(myTag, main_data->disc_year, ID3FID_YEAR);
                    set_TagField(myTag, s_track_num, ID3FID_TRACKNUM);
                    set_TagField(myTag, main_data->disc_category, ID3FID_CONTENTTYPE);
                    ID3Tag_UpdateByTagType(myTag, ID3TT_ID3V2);
                    ID3Tag_Delete(myTag);
                }
            }

            //dc: strcat() is for sissies!
            sprintf(&buffer[strlen(buffer)], "%d: %s\n", ++tracksdone, file_name_without_path(enc_file));

            // tm: basic playlist support - thanks to Mark Tyler
            if(config.cddb_config.create_playlist == TRUE)
            {
                if(fp_playlist == NULL)
                {
                    sprintf(playlist_filespec, "%s/playlist.m3u", file_path_without_name(enc_file));
                    fp_playlist = fopen(playlist_filespec, "w");
                }

                // if we succeeded above, we can now write to this
                if(fp_playlist != NULL)
                {
                    fprintf(fp_playlist, "%s\n", file_name_without_path(enc_file));
                }
            }
        }

        main_data->track[ i ].make_mp3 = FALSE;
    } /* end loop over all tracks */

    free(s_track_num);

    if((config.cddb_config.create_playlist == TRUE) && (fp_playlist != NULL))
    {
        fclose(fp_playlist);
    }

    /* Generate status message */
    sprintf(status_message, _("Tracks Completed: %2d\n\nArtist: %s\nAlbum: %s\n\n%s"),
            tracksdone, main_data->disc_artist, main_data->disc_title, buffer);

    /* show status pop up */
    if(madewavs)
    {
        status_handler(STAT_FINISH_WAV, status_message);
    }
    else if(mademp3s)
    {
        status_handler(STAT_FINISH_MP3, status_message);
    }

    /* Clear status bar */
    main_window_handler(MW_CLEAR_STATUSBAR, NULL, NULL);

    /* Destroy status widget */
    wm_status_frame_handler(WIDGET_DESTROY, WAV, NULL, NULL);

    /* Create select frame */
    select_frame_handler(WIDGET_CREATE, 0, main_data);
    main_window_handler(MW_MODE_SELECT, NULL, NULL);
}
コード例 #4
0
ファイル: xl2tpd.c プロジェクト: andy-padavan/rt-n56u
void death_handler (int signal)
{
    /*
       * If we get here, somebody terminated us with a kill or a control-c.
       * we call call_close on each tunnel twice to get a StopCCN out
       * for each one (we can't pause to make sure it's received.
       * Then we close the connections
     */
    struct tunnel *st, *st2;
    int sec;
    l2tp_log (LOG_INFO, "%s: Fatal signal %d received\n", __FUNCTION__, signal);
#ifdef USE_KERNEL
        if (kernel_support || signal != SIGTERM) {
#else
        if (signal != SIGTERM) {
#endif
                st = tunnels.head;
                while (st)
                {
                        st2 = st->next;
                        strcpy (st->self->errormsg, "Server closing");
                        sec = st->self->closing;
                        if (st->lac)
                                st->lac->redial = 0;
                        call_close (st->self);
                        if (!sec)
                        {
                                st->self->closing = -1;
                                call_close (st->self);
                        }
                        st = st2;
                }
        }

    /* erase pid and control files */
    unlink (gconfig.pidfile);
    unlink (gconfig.controlfile);

    free(dial_no_tmp);
    close(server_socket);
    close(control_fd);
    closelog();

    exit (1);
}

void sigterm_handler(int sig)
{
    sigterm_received = 1;
}

void sigint_handler(int sig)
{
    sigint_received = 1;
}

void sigchld_handler(int sig)
{
    sigchld_received = 1;
}

void sigusr1_handler(int sig)
{
    sigusr1_received = 1;
}

void sighup_handler(int sig)
{
    sighup_received = 1;
}

void process_signal(void)
{
    if (sigterm_received) { sigterm_received = 0; death_handler(SIGTERM); }
    if (sigint_received) { sigint_received = 0; death_handler(SIGINT); }
    if (sigchld_received) { sigchld_received = 0; child_handler(SIGCHLD); }
    if (sigusr1_received) { sigusr1_received = 0; status_handler(SIGUSR1); }
    if (sighup_received) { sighup_received = 0; null_handler(SIGHUP); }
}

int start_pppd (struct call *c, struct ppp_opts *opts)
{
    /* char a, b; */
    char tty[512];
    char *stropt[80];
    struct ppp_opts *p;
#ifdef USE_KERNEL
    struct sockaddr_pppol2tp sax;
    int flags;
#endif
    int pos = 1;
    int fd2 = -1;
#ifdef DEBUG_PPPD
    int x;
#endif
    struct termios ptyconf;
    struct call *sc;
    struct tunnel *st;

    p = opts;
    stropt[0] = strdup (PPPD);
    while (p)
    {
        stropt[pos] = (char *) malloc (strlen (p->option) + 1);
        strncpy (stropt[pos], p->option, strlen (p->option) + 1);
        pos++;
        p = p->next;
    }
    stropt[pos] = NULL;
    if (c->pppd > 0)
    {
        l2tp_log(LOG_WARNING, "%s: PPP already started on call!\n", __FUNCTION__);
        return -EINVAL;
    }
    if (c->fd > -1)
    {
        l2tp_log (LOG_WARNING, "%s: file descriptor already assigned!\n",
             __FUNCTION__);
        return -EINVAL;
    }

#ifdef USE_KERNEL
    if (kernel_support)
    {
       fd2 = socket(AF_PPPOX, SOCK_DGRAM, PX_PROTO_OL2TP);
       if (fd2 < 0) {
           l2tp_log (LOG_WARNING, "%s: Unable to allocate PPPoL2TP socket.\n",
                __FUNCTION__);
           return -EINVAL;
       }
       flags = fcntl(fd2, F_GETFL);
       if (flags == -1 || fcntl(fd2, F_SETFL, flags | O_NONBLOCK) == -1) {
           l2tp_log (LOG_WARNING, "%s: Unable to set PPPoL2TP socket nonblock.\n",
                __FUNCTION__);
           close(fd2);
           return -EINVAL;
       }
       memset(&sax, 0, sizeof(sax));
       sax.sa_family = AF_PPPOX;
       sax.sa_protocol = PX_PROTO_OL2TP;
       sax.pppol2tp.fd = c->container->udp_fd;
       sax.pppol2tp.addr.sin_addr.s_addr = c->container->peer.sin_addr.s_addr;
       sax.pppol2tp.addr.sin_port = c->container->peer.sin_port;
       sax.pppol2tp.addr.sin_family = AF_INET;
       sax.pppol2tp.s_tunnel  = c->container->ourtid;
       sax.pppol2tp.s_session = c->ourcid;
       sax.pppol2tp.d_tunnel  = c->container->tid;
       sax.pppol2tp.d_session = c->cid;
       if (connect(fd2, (struct sockaddr *)&sax, sizeof(sax)) < 0) {
           l2tp_log (LOG_WARNING, "%s: Unable to connect PPPoL2TP socket.\n",
                __FUNCTION__);
           close(fd2);
           return -EINVAL;
       }
       stropt[pos++] = strdup ("plugin");
       stropt[pos++] = strdup ("pppol2tp.so");
       stropt[pos++] = strdup ("pppol2tp");
       stropt[pos] = (char *) malloc (10);
       snprintf (stropt[pos], 10, "%d", fd2);
        pos++;
       if (c->container->lns) {
        stropt[pos++] = strdup ("pppol2tp_lns_mode");
        stropt[pos++] = strdup ("pppol2tp_tunnel_id");
        stropt[pos] = (char *) malloc (10);
        snprintf (stropt[pos], 10, "%d", c->container->ourtid);
            pos++;
        stropt[pos++] = strdup ("pppol2tp_session_id");
        stropt[pos] = (char *) malloc (10);
        snprintf (stropt[pos], 10, "%d", c->ourcid);
            pos++;
       }
        stropt[pos] = NULL;
    }
    else
#endif
    {
        if ((c->fd = getPtyMaster (tty, sizeof(tty))) < 0)
        {
            l2tp_log (LOG_WARNING, "%s: unable to allocate pty, abandoning!\n",
                      __FUNCTION__);
            return -EINVAL;
        } 

        /* set fd opened above to not echo so we don't see read our own packets
           back of the file descriptor that we just wrote them to */
        tcgetattr (c->fd, &ptyconf);
        ptyconf.c_cflag &= ~(ICANON | ECHO);
        ptyconf.c_lflag &= ~ECHO;
        tcsetattr (c->fd, TCSANOW, &ptyconf);
        if(fcntl(c->fd, F_SETFL, O_NONBLOCK)!=0) {
           l2tp_log(LOG_WARNING, "failed to set nonblock: %s\n", strerror(errno));
            return -EINVAL;
        }

        fd2 = open (tty, O_RDWR);
        if (fd2 < 0) {
            l2tp_log (LOG_WARNING, "unable to open tty %s, cannot start pppd", tty);
            return -EINVAL;
        }
        stropt[pos++] = strdup(tty);
        stropt[pos] = NULL;
    }

#ifdef DEBUG_PPPD
    l2tp_log (LOG_DEBUG, "%s: I'm running: \n", __FUNCTION__);
    for (x = 0; stropt[x]; x++)
    {
        l2tp_log (LOG_DEBUG, "\"%s\" \n", stropt[x]);
    };
#endif
#ifdef __uClinux__
    c->pppd = vfork ();
#else 
    c->pppd = fork ();
#endif

    if (c->pppd < 0)
    {
        /* parent */
        l2tp_log(LOG_WARNING,"%s: unable to fork(), abandoning!\n", __FUNCTION__);
        close(fd2);
        return -EINVAL;
    }
    else if (!c->pppd)
    {
        /* child */

        close (0); /* redundant; the dup2() below would do that, too */
        close (1); /* ditto */
        /* close (2); No, we want to keep the connection to /dev/null. */ 
#ifdef USE_KERNEL
       if (!kernel_support)
#endif
       {

        /* connect the pty to stdin and stdout */
        dup2 (fd2, 0);
        dup2 (fd2, 1);
	close(fd2);
       }
        /* close all the calls pty fds */
        st = tunnels.head;
        while (st)
        {
            sc = st->call_head;
            while (sc)
            {
#ifdef USE_KERNEL
                if (kernel_support) {
                    close(st->udp_fd); /* tunnel UDP fd */
                    close(st->pppox_fd); /* tunnel PPPoX fd */
                } else
#endif
                    close (sc->fd); /* call pty fd */
                sc = sc->next;
            }
            st = st->next;
        }

        /* close the UDP socket fd */
        if (server_socket > 0) {
            close (server_socket);
            server_socket = -1;
        }

        /* close the control pipe fd */
        if (control_fd > 0) {
            close (control_fd);
            control_fd = -1;
        }

        if( c->dialing[0] )
        {
            setenv( "CALLER_ID", c->dialing, 1 );
        }
        execv (PPPD, stropt);
        l2tp_log (LOG_WARNING, "%s: Exec of %s failed!\n", __FUNCTION__, PPPD);
        _exit (1);
    }
    close (fd2);
    pos = 0;
    while (stropt[pos])
    {
        free (stropt[pos]);
        pos++;
    };
    return 0;
}
コード例 #5
0
ファイル: SearchMemCacheI.cpp プロジェクト: bradenwu/oce
void FillFromDbCacheTask::handle() {
  try{
    int count, cycle, begin = 0,  maxid = -1;
    std::vector<LoadCache *>  _vecInvokeLoad; 
    std::vector<IceUtil::ThreadControl> thread_controls;
    std::vector<LoadCache *> threads; 
    for (int i=0; i<kInvokeLoadThreadNum; ++i) {
      boost::shared_ptr<IDbCache> db_cache = DatabaseCacheFactory::instance().getDbCache(SearchCacheManagerI::instance().getDSN());
      if(db_cache->Initialize()){
        LoadCache * loader = new LoadCache(db_cache);
        threads.push_back(loader);
        thread_controls.push_back(loader->start());
      }
      else  {
        MCE_WARN("Db initialize failed");
        return; 
      } 
    }
    //MCE_INFO("VEC thread size is "<<threads.size());
    if(threads.empty())
      return;


    count = begin;
    cycle = 0;
    MCE_INFO("start reading db...");
    TimeCost tc = TimeCost::create("load_data",1);
    while(count < LIMIT)  {
      std::vector<int> ids;
      Statement status_sql;
      if(maxid == begin)  {
        break;
      }
      status_sql << "SELECT " << USER_STATUS_FIELD << " FROM user_passport WHERE id > "
        << begin << " LIMIT " << IDS_BATCH_SIZE;
      maxid = begin;
      BasicStatusResultHandlerI status_handler(begin, ids);
      QueryRunner(DB_SEARCH2_USERBASIC_STATUS, CDbRServer).query(status_sql, status_handler);
      count += ids.size();
     
      //MCE_INFO("READ AFTER DB ids size is "<<ids.size());
      threads.at(cycle%threads.size())->invoke(ids);
      cycle++;

      MCE_INFO("cycle is "<< cycle<<" total : "<<count);
    }
    tc.step("Db load done!");
    for(vector<LoadCache *>::iterator it=threads.begin();it!=threads.end();++it){
      (*it)->stop();
    }
    for (vector<IceUtil::ThreadControl>::iterator i=thread_controls.begin(); i!=thread_controls.end(); ++i) {
      i->join();
    }
    tc.step("TT load done!");

        /*IDbResult* pDbResult = db_cache->Query();

        if (pDbResult == NULL) {
            MCE_WARN("don't iterator, because Query() return null pointer!");
            return;
        }

        long int uid = 0;
        
        while (BinStringPtr binObj = pDbResult->FetchObject(uid)) {
            if(!SearchCacheManagerI::instance().belongsMe(uid) || uid == 0) continue;
           
            MCE_DEBUG("userid is:"<<uid); 
            char* pBuf = NULL;
            int len = 0;

            binObj->getBuf(&pBuf, &len);

            if (pBuf==NULL || len <= 0) continue;

            SearchMemCacheDataPtr cachePtr = new SearchMemCacheData();
            //反序列化成内存cache
            if (!cachePtr->Unserialize(pBuf, len)) {
              continue;
            }

            //序列化成内存buf
            BinStringPtr binObj1 = cachePtr->Serialize();
            pBuf = NULL;
            len = 0;
            binObj1->getBuf(&pBuf, &len);
            if (pBuf==NULL || len <= 0) continue;
            //重新生成BinString的目的是压缩多分配的空间
            BinStringPtr binObj2 = new BinString(pBuf, len);


            MCE_DEBUG("loading userid=" << uid << "\t" << binObj->getBufferLen() << "\t" << binObj->getBufferCapacity() << "\t" << binObj2->getBufferLen() << "\t" << binObj2->getBufferCapacity());

            ObjectCacheHelper::instance().addObject(uid, binObj2);
            uid = 0;
        }
       */ 
        //db_cache->Close();
	}catch(...){
		MCE_WARN("FillTask done with exception");
	}
	SearchCacheManagerI::instance().setValid(true);
	MCE_INFO("FillTask done.");
}