<empty commit message>

This commit is contained in:
zribiahmed 2013-06-07 13:33:57 +00:00
parent 9d74ee5803
commit 122558bc79
5 changed files with 42 additions and 3 deletions

View file

@ -711,8 +711,8 @@ int cwmp_init(int argc, char** argv,struct cwmp *cwmp)
return error;
}
/* Only One instance should run*/
int pid_file = open("/var/run/cwmpd.pid", O_CREAT | O_RDWR, 0666);
int rc = flock(pid_file, LOCK_EX | LOCK_NB);
cwmp->pid_file = open("/var/run/cwmpd.pid", O_CREAT | O_RDWR, 0666);
int rc = flock(cwmp->pid_file, LOCK_EX | LOCK_NB);
if(rc) {
if(EWOULDBLOCK != errno)
{

View file

@ -488,6 +488,13 @@ void *thread_uloop_run (void *v)
return NULL;
}
void *thread_exit_program (void *v)
{
CWMP_LOG(INFO,"EXIT CWMP");
pthread_mutex_lock(&mutex_backup_session);
exit(EXIT_SUCCESS);
}
int main(int argc, char **argv)
{

View file

@ -38,6 +38,8 @@ struct search_keywords {
char *value;
};
extern pthread_mutex_t mutex_backup_session;
void bkp_session_save();
int cwmp_load_saved_session(struct cwmp *cwmp, char **acsurl, enum backup_loading load);
mxml_node_t *bkp_session_insert_event(int index, char *command_key, int id, char *status);

View file

@ -162,6 +162,7 @@ typedef struct cwmp {
pthread_cond_t threshold_periodic;
int retry_count_session;
struct list_head *head_event_container;
int pid_file;
} cwmp;
typedef struct session {
@ -201,5 +202,6 @@ void *thread_event_periodic (void *v);
void cwmp_add_notification (char *name, char *value, char *attribute, char *type);
int netlink_init(void);
char * mix_get_time(void);
void *thread_exit_program (void *v);
#endif /* _CWMP_H__ */

View file

@ -12,7 +12,7 @@
#include <unistd.h>
#include <libubus.h>
#include <sys/file.h>
#include "cwmp.h"
#include "ubus.h"
@ -115,6 +115,34 @@ cwmp_handle_command(struct ubus_context *ctx, struct ubus_object *obj,
blobmsg_add_u32(&b, "status", 0);
if (asprintf(&info, "freecwmp will execute the scheduled action commands at the end of the session") == -1)
return -1;
} else if (!strcmp("exit", cmd)) {
pthread_t exit_thread;
int error;
CWMP_LOG(INFO, "triggered ubus exit");
int rc = flock(cwmp_main.pid_file, LOCK_UN | LOCK_NB);
if(rc) {
char *piderr = "PID file unlock failed!";
fprintf(stderr, "%s\n", piderr);
CWMP_LOG(ERROR, piderr);
}
blobmsg_add_u32(&b, "status", 0);
if (asprintf(&info, "cwmpd daemon stopped") == -1)
return -1;
blobmsg_add_string(&b, "info", info);
free(info);
ubus_send_reply(ctx, req, b.head);
blob_buf_free(&b);
error = pthread_create(&exit_thread, NULL, &thread_exit_program, NULL);
if (error<0)
{
CWMP_LOG(ERROR,"Error when creating the exit thread!");
return -1;
}
return 0;
} else {
blobmsg_add_u32(&b, "status", -1);
if (asprintf(&info, "%s command is not supported", cmd) == -1)