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

View file

@ -529,7 +529,7 @@ void send_message()
if (crypto_kx_client_session_keys(shared_key, NULL, kp_from->pk.raw,
kp_from->sk, kp_to->pk.raw) != 0) {
/* 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);
@ -559,7 +559,7 @@ void send_message()
if (send_packet(pkt, sockfd) != ZSM_STA_SUCCESS) {
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));
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,
kp_from->sk, kp_to->pk.raw) != 0) {
/* 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 */
free(pkt.data);
if (crypto_aead_xchacha20poly1305_ietf_decrypt(decrypted, NULL, NULL,
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 {
/* Terminate decrypted data so we don't print random bytes */
decrypted[data_len] = '\0';
@ -120,7 +120,7 @@ void *receive_worker(void *arg)
int main()
{
if (sodium_init() < 0) {
write_log(LOG_ERROR, "Error initializing libsodium\n");
write_log(LOG_ERROR, "Error initializing libsodium");
}
/* Init libnotify with app name */
@ -152,12 +152,12 @@ int main()
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) {
/* Fatal */
error(1, "Error authenticating with server");
} else {
write_log(LOG_INFO, "Authenticated to server as %s\n", USERNAME);
write_log(LOG_INFO, "Authenticated to server as %s", USERNAME);
}