Deleted Added
1
2/*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) NGINX, Inc.
5 */
6
7#include <nxt_main.h>
8#include <nxt_runtime.h>

--- 165 unchanged lines hidden (view full) ---

174 nxt_port_t *port;
175 nxt_conf_value_t *conf;
176 nxt_common_app_conf_t app_conf;
177
178 static nxt_str_t nobody = nxt_string("nobody");
179
180 ret = NXT_ERROR;
181
182 b = msg->buf;
183
184 nxt_debug(task, "main start worker: %*s", b->mem.free - b->mem.pos,
185 b->mem.pos);
186
187 mp = nxt_mp_create(1024, 128, 256, 32);
188
189 nxt_memzero(&app_conf, sizeof(nxt_common_app_conf_t));
190
191 start = b->mem.pos;
192
193 app_conf.name.start = start;
194 app_conf.name.length = nxt_strlen(start);
195
196 start += app_conf.name.length + 1;

--- 619 unchanged lines hidden (view full) ---

816 nxt_sockaddr_t *sa;
817 nxt_port_msg_type_t type;
818 nxt_listening_socket_t ls;
819 u_char message[2048];
820
821 b = msg->buf;
822 sa = (nxt_sockaddr_t *) b->mem.pos;
823
824 out = NULL;
825
826 ls.socket = -1;
827 ls.error = NXT_SOCKET_ERROR_SYSTEM;
828 ls.start = message;
829 ls.end = message + sizeof(message);
830
831 port = nxt_runtime_port_find(task->thread->runtime, msg->port_msg.pid,

--- 200 unchanged lines hidden (view full) ---

1032 }
1033
1034 b = msg->buf;
1035
1036 if (b == NULL) {
1037 return;
1038 }
1039
1040 nxt_debug(task, "application languages: \"%*s\"",
1041 b->mem.free - b->mem.pos, b->mem.pos);
1042
1043 mp = nxt_mp_create(1024, 128, 256, 32);
1044 if (mp == NULL) {
1045 return;
1046 }
1047
1048 conf = nxt_conf_json_parse(mp, b->mem.pos, b->mem.free, NULL);
1049 if (conf == NULL) {
1050 goto fail;
1051 }
1052
1053 root = nxt_conf_get_path(conf, &root_path);
1054 if (root == NULL) {
1055 goto fail;

--- 70 unchanged lines hidden (view full) ---

1126
1127 return -n;
1128}
1129
1130
1131static void
1132nxt_main_port_conf_store_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg)
1133{
1134 ssize_t n, size;
1135 nxt_buf_t *b;
1136 nxt_int_t ret;
1137 nxt_file_t file;
1138 nxt_runtime_t *rt;
1139
1140 nxt_memzero(&file, sizeof(nxt_file_t));
1141
1142 rt = task->thread->runtime;
1143
1144 file.name = (nxt_file_name_t *) rt->conf_tmp;
1145
1146 if (nxt_slow_path(nxt_file_open(task, &file, NXT_FILE_WRONLY,
1147 NXT_FILE_TRUNCATE, NXT_FILE_OWNER_ACCESS)
1148 != NXT_OK))
1149 {
1150 goto error;
1151 }
1152
1153 for (b = msg->buf; b != NULL; b = b->next) {
1154 size = nxt_buf_mem_used_size(&b->mem);
1155
1156 n = nxt_file_write(&file, b->mem.pos, size, 0);
1157
1158 if (nxt_slow_path(n != size)) {
1159 nxt_file_close(task, &file);
1160 (void) nxt_file_delete(file.name);
1161 goto error;
1162 }
1163 }
1164
1165 nxt_file_close(task, &file);
1166
1167 ret = nxt_file_rename(file.name, (nxt_file_name_t *) rt->conf);
1168
1169 if (nxt_fast_path(ret == NXT_OK)) {
1170 return;
1171 }
1172
1173error:
1174
1175 nxt_log(task, NXT_LOG_ALERT, "failed to store current configuration");
1176}