Changeset 4156


Ignore:
Timestamp:
12/19/10 01:08:48 (12 years ago)
Author:
schlocke
Message:

oscam restart by webif

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/globals.h

    r4144 r4156  
    12941294
    12951295// oscam
     1296extern void cs_exit_oscam();
     1297extern void cs_restart_oscam();
    12961298extern int recv_from_udpipe(uchar *);
    12971299extern char* username(struct s_client *);
  • trunk/oscam-config.h

    r4140 r4156  
    88
    99#ifndef WITH_SSL
    10 //#define WITH_SSL
     10#define WITH_SSL
    1111#endif
    1212
  • trunk/oscam-http.c

    r4155 r4156  
    22702270        running = 0;
    22712271
    2272         struct s_client *cl;
    2273         for (cl=first_client->next; cl ; cl=cl->next)
    2274             kill_thread(cl);
    2275         exit(SIGQUIT);
     2272        cs_exit_oscam();
     2273    }
     2274    else if (strcmp(getParam(params, "action"), "Restart") == 0) {
     2275        tpl_addVar(vars, 0, "STYLESHEET", CSS);
     2276        tpl_printf(vars, 0, "REFRESHTIME", "%d", 1);
     2277        tpl_addVar(vars, 0, "REFRESHURL", "status.html");
     2278        tpl_addVar(vars, 0, "REFRESH", tpl_getTpl(vars, "REFRESH"));
     2279        tpl_printf(vars, 0, "SECONDS", "%d", 1);
     2280        webif_write(tpl_getTpl(vars, "SHUTDOWN"), f);
     2281        running = 0;
     2282       
     2283        cs_restart_oscam();
     2284       
    22762285    } else {
    22772286        webif_write(tpl_getTpl(vars, "PRESHUTDOWN"), f);
     
    29902999    cs_log("HTTP Server: Shutdown requested from %s", inet_ntoa(*(struct in_addr *)&remote.sin_addr));
    29913000    close(sock);
    2992     exit(SIGQUIT);
     3001    //exit(SIGQUIT);
    29933002}
    29943003#endif
  • trunk/oscam.c

    r4151 r4156  
    2020        Globals
    2121*****************************************************************************/
     22int exit_oscam=0;
    2223struct s_module ph[CS_MAX_MOD]; // Protocols
    2324struct s_cardsystem cardsystem[CS_MAX_MOD]; // Protocols
     
    574575
    575576    NULLFREE(cl);
    576 
    577     exit(sig);  //clears all threads
    578577}
    579578
     
    29972996}
    29982997
     2998#ifdef WEBIF
     2999static void restart_daemon()
     3000{
     3001  while (1) {
     3002 
     3003    //start client process:
     3004    pid_t pid = fork();
     3005    if (!pid)
     3006      return; //client process=oscam process
     3007    if (pid < 0)
     3008      exit(1);
     3009   
     3010    //restart control process:
     3011    int res=0;
     3012    int status=0;
     3013    do {
     3014      res = waitpid(pid, &status, 0);
     3015      if (res==-1) {
     3016        if (errno!=EINTR)
     3017          exit(1);
     3018      }
     3019    } while (res!=pid);
     3020
     3021    status = WEXITSTATUS(status);
     3022   
     3023    //status=99 restart oscam, all other->terminate
     3024    if (status!=99) {
     3025      exit(status);
     3026    }
     3027  }
     3028}
     3029#endif
    29993030
    30003031int main (int argc, char *argv[])
    30013032{
    3002 
    30033033
    30043034if (pthread_key_create(&getclient, NULL)) {
     
    31263156      }
    31273157  }
     3158
     3159#ifdef OS_MACOSX
     3160  if (bg && daemon_compat(1,0))
     3161#else
     3162  if (bg && daemon(1,0))
     3163#endif
     3164  {
     3165    cs_log("Error starting in background (errno=%d: %s)", errno, strerror(errno));
     3166    cs_exit(1);
     3167  }
     3168
     3169#ifdef WEBIF
     3170  restart_daemon(); 
     3171#endif
     3172
    31283173  if (cs_confdir[strlen(cs_confdir)]!='/') strcat(cs_confdir, "/");
    31293174  init_shm();
     
    31733218  first_client->fd_m2c_c=mfdr;
    31743219
    3175 #ifdef OS_MACOSX
    3176   if (bg && daemon_compat(1,0))
    3177 #else
    3178   if (bg && daemon(1,0))
    3179 #endif
    3180   {
    3181     cs_log("Error starting in background (errno=%d: %s)", errno, strerror(errno));
    3182     cs_exit(1);
    3183   }
    3184 
    31853220  write_versionfile();
    31863221  server_pid = getpid();
     
    32483283
    32493284    //cs_close_log();
    3250     while (1) {
     3285    while (!exit_oscam) {
    32513286        fd_set fds;
    32523287
    32533288        do {
     3289                //timeout value for checking exit_oscam:
     3290                        struct timeval timeout;
     3291                        timeout.tv_sec = 1;
     3292                        timeout.tv_usec = 0;
     3293                       
     3294                        //Wait for incoming data
    32543295            FD_ZERO(&fds);
    32553296            FD_SET(mfdr, &fds);
     
    32603301                            FD_SET(ph[i].ptab->ports[j].fd, &fds);
    32613302            errno=0;
    3262             select(gfd, &fds, 0, 0, 0);
    3263         } while (errno==EINTR);
    3264 
     3303            select(gfd, &fds, 0, 0, &timeout);
     3304        } while (errno==EINTR && !exit_oscam); //if timeout accurs and exit_oscam is set, we break the loop
     3305       
     3306        if (exit_oscam)
     3307                break;
     3308         
    32653309        first_client->last=time((time_t *)0);
    32663310
     
    32793323    }
    32803324
     3325        //can't kill? running endless...
     3326    //struct s_client *cl;
     3327    //for (cl=first_client->next;cl;cl=cl->next)
     3328    //  kill_thread(cl);
     3329     
    32813330#ifdef AZBOX
    32823331  if (openxcas_close() < 0) {
     
    32853334#endif
    32863335
    3287     cs_exit(1);
    3288 }
     3336    cs_exit(exit_oscam);
     3337    return exit_oscam;
     3338}
     3339
     3340#ifdef WEBIF
     3341void cs_exit_oscam()
     3342{
     3343  exit_oscam=1;
     3344  cs_log("exit oscam requested");
     3345}
     3346
     3347void cs_restart_oscam()
     3348{
     3349  exit_oscam=99;
     3350  cs_log("restart oscam requested");
     3351}
     3352#endif
    32893353
    32903354#ifdef CS_LED
Note: See TracChangeset for help on using the changeset viewer.