nxt_main_process.c (349:ae438f16b44e) nxt_main_process.c (352:47649fbbcb53)
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
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;
182 mp = nxt_mp_create(1024, 128, 256, 32);
183
183
184 if (nxt_slow_path(mp == NULL)) {
185 return;
186 }
187
188 b = nxt_buf_chk_make_plain(mp, msg->buf, msg->size);
189
190 if (b == NULL) {
191 return;
192 }
193
184 nxt_debug(task, "main start worker: %*s", b->mem.free - b->mem.pos,
185 b->mem.pos);
186
194 nxt_debug(task, "main start worker: %*s", b->mem.free - b->mem.pos,
195 b->mem.pos);
196
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
197 nxt_memzero(&app_conf, sizeof(nxt_common_app_conf_t));
198
199 start = b->mem.pos;
200
201 app_conf.name.start = start;
202 app_conf.name.length = nxt_strlen(start);
203
204 start += app_conf.name.length + 1;

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

824 nxt_sockaddr_t *sa;
825 nxt_port_msg_type_t type;
826 nxt_listening_socket_t ls;
827 u_char message[2048];
828
829 b = msg->buf;
830 sa = (nxt_sockaddr_t *) b->mem.pos;
831
832 /* TODO check b size and make plain */
833
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
834 out = NULL;
835
836 ls.socket = -1;
837 ls.error = NXT_SOCKET_ERROR_SYSTEM;
838 ls.start = message;
839 ls.end = message + sizeof(message);
840
841 port = nxt_runtime_port_find(task->thread->runtime, msg->port_msg.pid,

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

1042 }
1043
1044 b = msg->buf;
1045
1046 if (b == NULL) {
1047 return;
1048 }
1049
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
1050 mp = nxt_mp_create(1024, 128, 256, 32);
1051 if (mp == NULL) {
1052 return;
1053 }
1054
1055 b = nxt_buf_chk_make_plain(mp, b, msg->size);
1056
1057 if (b == NULL) {
1058 return;
1059 }
1060
1061 nxt_debug(task, "application languages: \"%*s\"",
1062 b->mem.free - b->mem.pos, b->mem.pos);
1063
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{
1064 conf = nxt_conf_json_parse(mp, b->mem.pos, b->mem.free, NULL);
1065 if (conf == NULL) {
1066 goto fail;
1067 }
1068
1069 root = nxt_conf_get_path(conf, &root_path);
1070 if (root == NULL) {
1071 goto fail;

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

1142
1143 return -n;
1144}
1145
1146
1147static void
1148nxt_main_port_conf_store_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg)
1149{
1134 ssize_t n, size;
1150 ssize_t n, size, offset;
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
1151 nxt_buf_t *b;
1152 nxt_int_t ret;
1153 nxt_file_t file;
1154 nxt_runtime_t *rt;
1155
1156 nxt_memzero(&file, sizeof(nxt_file_t));
1157
1158 rt = task->thread->runtime;
1159
1160 file.name = (nxt_file_name_t *) rt->conf_tmp;
1161
1162 if (nxt_slow_path(nxt_file_open(task, &file, NXT_FILE_WRONLY,
1163 NXT_FILE_TRUNCATE, NXT_FILE_OWNER_ACCESS)
1164 != NXT_OK))
1165 {
1166 goto error;
1167 }
1168
1169 offset = 0;
1170
1153 for (b = msg->buf; b != NULL; b = b->next) {
1154 size = nxt_buf_mem_used_size(&b->mem);
1155
1171 for (b = msg->buf; b != NULL; b = b->next) {
1172 size = nxt_buf_mem_used_size(&b->mem);
1173
1156 n = nxt_file_write(&file, b->mem.pos, size, 0);
1174 n = nxt_file_write(&file, b->mem.pos, size, offset);
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 }
1175
1176 if (nxt_slow_path(n != size)) {
1177 nxt_file_close(task, &file);
1178 (void) nxt_file_delete(file.name);
1179 goto error;
1180 }
1181
1182 offset += n;
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}
1183 }
1184
1185 nxt_file_close(task, &file);
1186
1187 ret = nxt_file_rename(file.name, (nxt_file_name_t *) rt->conf);
1188
1189 if (nxt_fast_path(ret == NXT_OK)) {
1190 return;
1191 }
1192
1193error:
1194
1195 nxt_log(task, NXT_LOG_ALERT, "failed to store current configuration");
1196}