OpenBSD: Simplify promise creation after seprintf() introduction

Just truncate the initial promises back to the final ones after pledging
for the first time, saving code and memory.

Assign `ptr' in all initial `seprintf()' calls for consistency while
here.
weechat-hashes
Klemens Nanni 2021-06-14 21:37:07 +00:00 committed by C. McEnroe
parent 3e0b38e48e
commit b690bd0b83
1 changed files with 4 additions and 5 deletions

9
chat.c
View File

@ -295,10 +295,9 @@ int main(int argc, char *argv[]) {
if (logEnable) ptr = seprintf(ptr, end, " wpath cpath"); if (logEnable) ptr = seprintf(ptr, end, " wpath cpath");
if (!self.restricted) ptr = seprintf(ptr, end, " proc exec"); if (!self.restricted) ptr = seprintf(ptr, end, " proc exec");
char *promisesFinal = strdup(promises); char *promisesInitial = ptr;
if (!promisesFinal) err(EX_OSERR, "strdup");
seprintf(ptr, end, " inet dns"); ptr = seprintf(ptr, end, " inet dns");
int error = pledge(promises, NULL); int error = pledge(promises, NULL);
if (error) err(EX_OSERR, "pledge"); if (error) err(EX_OSERR, "pledge");
#endif #endif
@ -316,9 +315,9 @@ int main(int argc, char *argv[]) {
int irc = ircConnect(bind, host, port); int irc = ircConnect(bind, host, port);
#ifdef __OpenBSD__ #ifdef __OpenBSD__
error = pledge(promisesFinal, NULL); *promisesInitial = '\0';
error = pledge(promises, NULL);
if (error) err(EX_OSERR, "pledge"); if (error) err(EX_OSERR, "pledge");
free(promisesFinal);
#endif #endif
if (pass) ircFormat("PASS :%s\r\n", pass); if (pass) ircFormat("PASS :%s\r\n", pass);