Make write_log print new line by default

This commit is contained in:
Night Kaly 2024-09-24 19:10:56 +01:00
parent b84a664669
commit 294662e2ae
Signed by: night0721
GPG key ID: 957D67B8DB7A119B
3 changed files with 13 additions and 13 deletions

View file

@ -40,7 +40,7 @@ void *memalloc(size_t size)
{ {
void *ptr = malloc(size); void *ptr = malloc(size);
if (!ptr) { if (!ptr) {
write_log(LOG_ERROR, "Error allocating memory\n"); write_log(LOG_ERROR, "Error allocating memory");
return NULL; return NULL;
} }
return ptr; return ptr;
@ -50,7 +50,7 @@ void *estrdup(void *str)
{ {
void *modstr = strdup(str); void *modstr = strdup(str);
if (modstr == NULL) { if (modstr == NULL) {
write_log(LOG_ERROR, "Error allocating memory\n"); write_log(LOG_ERROR, "Error allocating memory");
return NULL; return NULL;
} }
return modstr; return modstr;
@ -64,7 +64,7 @@ char *replace_home(char *str)
{ {
char *home = getenv("HOME"); char *home = getenv("HOME");
if (home == NULL) { if (home == NULL) {
write_log(LOG_ERROR, "$HOME not defined\n"); write_log(LOG_ERROR, "$HOME not defined");
return str; return str;
} }
char *newstr = memalloc(strlen(str) + strlen(home)); char *newstr = memalloc(strlen(str) + strlen(home));
@ -85,7 +85,7 @@ void mkdir_p(const char *destdir)
if (destdir[0] == '~') { if (destdir[0] == '~') {
char *home = getenv("HOME"); char *home = getenv("HOME");
if (home == NULL) { if (home == NULL) {
write_log(LOG_ERROR, "$HOME not defined\n"); write_log(LOG_ERROR, "$HOME not defined");
return; return;
} }
/* replace ~ with home */ /* replace ~ with home */
@ -111,7 +111,7 @@ void mkdir_p(const char *destdir)
continue; continue;
} }
write_log(LOG_ERROR, "mkdir failed: %s\n", strerror(errno)); write_log(LOG_ERROR, "mkdir failed: %s", strerror(errno));
free(path); free(path);
return; return;
} }
@ -148,7 +148,7 @@ void write_log(int type, const char *fmt, ...)
strftime(time, 22, "%Y-%m-%d %H:%M:%S ", t); strftime(time, 22, "%Y-%m-%d %H:%M:%S ", t);
char details[2 + type_len + 22]; char details[2 + type_len + 22];
snprintf(details, 2 + type_len + 22, "%s%s", logtype, time); snprintf(details, 2 + type_len + 22, "%s%s", logtype, time);
fprintf(log, details); fprintf(log, "%s\n", details);
vfprintf(log, fmt, args); vfprintf(log, fmt, args);
fclose(log); fclose(log);
} }

View file

@ -529,7 +529,7 @@ void send_message()
if (crypto_kx_client_session_keys(shared_key, NULL, kp_from->pk.raw, if (crypto_kx_client_session_keys(shared_key, NULL, kp_from->pk.raw,
kp_from->sk, kp_to->pk.raw) != 0) { kp_from->sk, kp_to->pk.raw) != 0) {
/* Recipient public key is suspicious */ /* Recipient public key is suspicious */
write_log(LOG_ERROR, "Error performing key exchange with %s\n", recipient); write_log(LOG_ERROR, "Error performing key exchange with %s", recipient);
} }
size_t content_len = strlen(content); size_t content_len = strlen(content);
@ -559,7 +559,7 @@ void send_message()
if (send_packet(pkt, sockfd) != ZSM_STA_SUCCESS) { if (send_packet(pkt, sockfd) != ZSM_STA_SUCCESS) {
close(sockfd); close(sockfd);
write_log(LOG_ERROR, "Failed to send message\n"); write_log(LOG_ERROR, "Failed to send message");
} }
add_message(USERNAME, recipient, content, content_len, time(NULL)); add_message(USERNAME, recipient, content, content_len, time(NULL));
free_packet(pkt); free_packet(pkt);

View file

@ -96,14 +96,14 @@ void *receive_worker(void *arg)
if (crypto_kx_client_session_keys(shared_key, NULL, kp_from->pk.raw, if (crypto_kx_client_session_keys(shared_key, NULL, kp_from->pk.raw,
kp_from->sk, kp_to->pk.raw) != 0) { kp_from->sk, kp_to->pk.raw) != 0) {
/* Suspicious server public key, bail out */ /* Suspicious server public key, bail out */
write_log(LOG_ERROR, "Error performing key exchange with %s\n", from); write_log(LOG_ERROR, "Error performing key exchange with %s", from);
} }
/* We don't need it anymore */ /* We don't need it anymore */
free(pkt.data); free(pkt.data);
if (crypto_aead_xchacha20poly1305_ietf_decrypt(decrypted, NULL, NULL, if (crypto_aead_xchacha20poly1305_ietf_decrypt(decrypted, NULL, NULL,
encrypted, cipher_len, NULL, 0, nonce, shared_key) != 0) { encrypted, cipher_len, NULL, 0, nonce, shared_key) != 0) {
write_log(LOG_ERROR, "Unable to decrypt data from %s\n", from); write_log(LOG_ERROR, "Unable to decrypt data from %s", from);
} else { } else {
/* Terminate decrypted data so we don't print random bytes */ /* Terminate decrypted data so we don't print random bytes */
decrypted[data_len] = '\0'; decrypted[data_len] = '\0';
@ -120,7 +120,7 @@ void *receive_worker(void *arg)
int main() int main()
{ {
if (sodium_init() < 0) { if (sodium_init() < 0) {
write_log(LOG_ERROR, "Error initializing libsodium\n"); write_log(LOG_ERROR, "Error initializing libsodium");
} }
/* Init libnotify with app name */ /* Init libnotify with app name */
@ -152,12 +152,12 @@ int main()
return 0; return 0;
} }
write_log(LOG_INFO, "Connected to server at %s\n", DOMAIN); write_log(LOG_INFO, "Connected to server at %s", DOMAIN);
if (authenticate_server(&sockfd) != ZSM_STA_SUCCESS) { if (authenticate_server(&sockfd) != ZSM_STA_SUCCESS) {
/* Fatal */ /* Fatal */
error(1, "Error authenticating with server"); error(1, "Error authenticating with server");
} else { } else {
write_log(LOG_INFO, "Authenticated to server as %s\n", USERNAME); write_log(LOG_INFO, "Authenticated to server as %s", USERNAME);
} }