int do_file_sync(struct config_instance_t * inst , int work_idx , __u8 * msg_buff , int file_fd , char * send_dir , struct dir_instance_t * dir_curr) { msg_data_t * msg; int i; struct remote_ip_t * rip; int ret; char record_signle_name[512] = ""; msg = load_msg(file_fd, MSG_TYPE_SYNC_DATA, inst->fileid, dir_curr->blockid, block_size, msg_buff); if (!msg){ print_debug("load msg for block %d fail\n" , dir_curr->blockid); return -1; } if (dir_curr->broadcast == 0xffffffff){ all_load_cnt++; for (i = 0; i < inst->ipcnt; i++){ rip = inst->remoteip + i; if (rip->sockfd[work_idx] != -1) { ret = send_msg(msg, rip , work_idx , file_fd); if (ret <= 0){ rip->sockfd[work_idx] = -1; sprintf(record_signle_name, "%s/sgl+%d+%s", send_dir, dir_curr->blockid, rip->ipname); vmsync_file_create(record_signle_name); sgl_create_cnt++; } }else{ sprintf(record_signle_name, "%s/sgl+%d+%s", send_dir, dir_curr->blockid, rip->ipname); vmsync_file_create(record_signle_name); } } all_del_cnt++; vmsync_file_remove(dir_curr->filename); }else{ sgl_load_cnt++; for (i = 0; i < inst->ipcnt; i++){ rip = inst->remoteip + i; if ((rip->sockfd[work_idx] != -1) && (rip->ip == dir_curr->broadcast) ){ ret = send_msg(msg, rip , work_idx , file_fd); if (ret <= 0){ rip->sockfd[work_idx] = -1; }else{ sgl_del_cnt++; vmsync_file_remove(dir_curr->filename); } } } } return 0; }
/** load msg cache */ static int load_msg_cache(SSL* ssl, struct worker* worker) { sldns_buffer* buf = worker->env.scratch_buffer; if(!read_fixed(ssl, buf, "START_MSG_CACHE")) return 0; while(ssl_read_buf(ssl, buf) && strcmp((char*)sldns_buffer_begin(buf), "END_MSG_CACHE")!=0) { if(!load_msg(ssl, buf, worker)) return 0; } return 1; }
long do_msgsnd(int msqid, long mtype, void __user *mtext, size_t msgsz, int msgflg) { struct msg_queue *msq; struct msg_msg *msg; int err; struct ipc_namespace *ns; ns = current->nsproxy->ipc_ns; if (msgsz > ns->msg_ctlmax || (long) msgsz < 0 || msqid < 0) return -EINVAL; if (mtype < 1) return -EINVAL; msg = load_msg(mtext, msgsz); if (IS_ERR(msg)) return PTR_ERR(msg); msg->m_type = mtype; msg->m_ts = msgsz; msq = msg_lock_check(ns, msqid); if (IS_ERR(msq)) { err = PTR_ERR(msq); goto out_free; } for (;;) { struct msg_sender s; err = -EACCES; if (ipcperms(&msq->q_perm, S_IWUGO)) goto out_unlock_free; err = security_msg_queue_msgsnd(msq, msg, msgflg); if (err) goto out_unlock_free; if (msgsz + msq->q_cbytes <= msq->q_qbytes && 1 + msq->q_qnum <= msq->q_qbytes) { break; } /* queue full, wait: */ if (msgflg & IPC_NOWAIT) { err = -EAGAIN; goto out_unlock_free; } ss_add(msq, &s); ipc_rcu_getref(msq); msg_unlock(msq); schedule(); ipc_lock_by_ptr(&msq->q_perm); ipc_rcu_putref(msq); if (msq->q_perm.deleted) { err = -EIDRM; goto out_unlock_free; } ss_del(&s); if (signal_pending(current)) { err = -ERESTARTNOHAND; goto out_unlock_free; } } msq->q_lspid = task_tgid_vnr(current); msq->q_stime = get_seconds(); if (!pipelined_send(msq, msg)) { /* noone is waiting for this message, enqueue it */ list_add_tail(&msg->m_list, &msq->q_messages); msq->q_cbytes += msgsz; msq->q_qnum++; atomic_add(msgsz, &ns->msg_bytes); atomic_inc(&ns->msg_hdrs); } err = 0; msg = NULL; out_unlock_free: msg_unlock(msq); out_free: if (msg != NULL) free_msg(msg); return err; }
/* initialise the message translation subsystem. If the "lang" argument is NULL then get the language from the normal environment variables */ BOOL lang_tdb_init(const char *lang) { char *path = NULL; char *msg_path = NULL; struct stat st; static int initialised; time_t loadtime; BOOL result = False; /* we only want to init once per process, unless given an override */ if (initialised && !lang) return True; if (initialised) { /* we are re-initialising, free up any old init */ if (tdb) { tdb_close(tdb); tdb = NULL; } SAFE_FREE(current_lang); } initialised = 1; if (!lang) { /* no lang given, use environment */ lang = get_lang(); } /* if no lang then we don't translate */ if (!lang) return True; asprintf(&msg_path, "%s.msg", lib_path((const char *)lang)); if (stat(msg_path, &st) != 0) { /* the msg file isn't available */ DEBUG(10, ("lang_tdb_init: %s: %s\n", msg_path, strerror(errno))); goto done; } asprintf(&path, "%s%s.tdb", lock_path("lang_"), lang); DEBUG(10, ("lang_tdb_init: loading %s\n", path)); tdb = tdb_open_log(path, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0644); if (!tdb) { tdb = tdb_open_log(path, 0, TDB_DEFAULT, O_RDONLY, 0); if (!tdb) { DEBUG(10, ("lang_tdb_init: %s: %s\n", path, strerror(errno))); goto done; } current_lang = SMB_STRDUP(lang); result = True; goto done; } loadtime = tdb_fetch_int32(tdb, "/LOADTIME/"); if (loadtime == -1 || loadtime < st.st_mtime) { load_msg(msg_path); tdb_store_int32(tdb, "/LOADTIME/", (int)time(NULL)); } current_lang = SMB_STRDUP(lang); result = True; done: SAFE_FREE(msg_path); SAFE_FREE(path); return result; }
asmlinkage long sys_msgsnd (int msqid, struct msgbuf *msgp, size_t msgsz, int msgflg) { struct msg_queue *msq; struct msg_msg *msg; long mtype; int err; if (msgsz > msg_ctlmax || (long) msgsz < 0 || msqid < 0) return -EINVAL; if (get_user(mtype, &msgp->mtype)) return -EFAULT; if (mtype < 1) return -EINVAL; msg = load_msg(msgp->mtext, msgsz); if(IS_ERR(msg)) return PTR_ERR(msg); msg->m_type = mtype; msg->m_ts = msgsz; msq = msg_lock(msqid); err=-EINVAL; if(msq==NULL) goto out_free; retry: err= -EIDRM; if (msg_checkid(msq,msqid)) goto out_unlock_free; err=-EACCES; if (ipcperms(&msq->q_perm, S_IWUGO)) goto out_unlock_free; if(msgsz + msq->q_cbytes > msq->q_qbytes || 1 + msq->q_qnum > msq->q_qbytes) { struct msg_sender s; if(msgflg&IPC_NOWAIT) { err=-EAGAIN; goto out_unlock_free; } ss_add(msq, &s); msg_unlock(msqid); schedule(); current->state= TASK_RUNNING; msq = msg_lock(msqid); err = -EIDRM; if(msq==NULL) goto out_free; ss_del(&s); if (signal_pending(current)) { err=-EINTR; goto out_unlock_free; } goto retry; } msq->q_lspid = current->pid; msq->q_stime = CURRENT_TIME; if(!pipelined_send(msq,msg)) { /* noone is waiting for this message, enqueue it */ list_add_tail(&msg->m_list,&msq->q_messages); msq->q_cbytes += msgsz; msq->q_qnum++; atomic_add(msgsz,&msg_bytes); atomic_inc(&msg_hdrs); } err = 0; msg = NULL; out_unlock_free: msg_unlock(msqid); out_free: if(msg!=NULL) free_msg(msg); return err; }