aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorturret <turret@duck.com>2023-12-18 16:13:36 -0600
committerturret <turret@duck.com>2023-12-18 16:13:36 -0600
commit54b308af97b91ceabb0a482f325d3a8595b01aa3 (patch)
treeadbe345bca29943f02f54c86dc1ec17d5aa3528a
parent22cacb4dc96faae8814a9696805314c0fcc455ba (diff)
downloaddiscord-bot-skeleton-54b308af97b91ceabb0a482f325d3a8595b01aa3.tar.gz
discord-bot-skeleton-54b308af97b91ceabb0a482f325d3a8595b01aa3.tar.bz2
discord-bot-skeleton-54b308af97b91ceabb0a482f325d3a8595b01aa3.zip
*: enforce 78 char line limit
-rw-r--r--init/init.c13
-rw-r--r--init/log.c20
-rw-r--r--init/subsys.c10
-rw-r--r--net/api.c3
-rw-r--r--net/net.c18
5 files changed, 43 insertions, 21 deletions
diff --git a/init/init.c b/init/init.c
index c2ae3c4..e2ece8a 100644
--- a/init/init.c
+++ b/init/init.c
@@ -45,7 +45,9 @@ static void do_initcall_level(int level)
{
initcall_entry_t *fn;
- for (fn = initcall_levels[level - 1]; fn < initcall_levels[level]; fn++)
+ for (fn = initcall_levels[level - 1];
+ fn < initcall_levels[level];
+ fn++)
initcall_from_entry(fn)();
}
@@ -61,7 +63,8 @@ int main(void)
{
print("init: Hello world! Running " NAME " v" VERSION "!");
- /* set mainpid for the subsystem service so it is fully accessible during l1 */
+ /* set mainpid for the subsystem service so it is fully accessible
+ during l1 */
mainpid = getpid();
/* set stack_size for subsystem service */
@@ -77,7 +80,8 @@ int main(void)
if(!token_base)
panic("init: cannot find TOKEN in env");
- token = calloc(strlen(token_base) + strlen("Authorization: Bot ") + 1, sizeof(char));
+ token = calloc(strlen(token_base) + strlen("Authorization: Bot ") + 1,
+ sizeof(char));
strcpy(token, "Authorization: Bot ");
strcat(token, token_base);
@@ -97,7 +101,8 @@ int main(void)
int process = 0;
while((process = waitpid(-1, NULL, WNOHANG)) > 0)
if(subsystem_handle_term(process) > 0)
- print(LOG_WARNING "init: failed to reap process %d", process);
+ print(LOG_WARNING "init: failed to reap process %d",
+ process);
}
}
diff --git a/init/log.c b/init/log.c
index aba141d..75840a2 100644
--- a/init/log.c
+++ b/init/log.c
@@ -8,7 +8,6 @@
#include <sys/syscall.h>
#include <sys/time.h>
#include <unistd.h>
-
#include <log.h>
#include <util.h>
@@ -72,7 +71,8 @@ static int vaprint(const char *fmt, va_list ap)
char tsbuf[64] = "\0";
struct timeval time;
gettimeofday(&time, NULL);
- snprintf(tsbuf, sizeof(tsbuf), "[%5ld.%06ld] ", (long)time.tv_sec % 100000, (long)time.tv_usec);
+ snprintf(tsbuf, sizeof(tsbuf), "[%5ld.%06ld] ",
+ (long)time.tv_sec % 100000, (long)time.tv_usec);
/* spin lock, at the cost of architecture portability
concurrency is something that we need to adjust for, and the
@@ -112,7 +112,9 @@ static int vaprint(const char *fmt, va_list ap)
return 0;
}
-void _panic(const char *fileorigin, const int lineorigin, const char *fmt, ...)
+void _panic(const char *fileorigin,
+ const int lineorigin,
+ const char *fmt, ...)
{
char mode = PANICMODE_DIE;
int pid = getpid();
@@ -132,7 +134,8 @@ void _panic(const char *fileorigin, const int lineorigin, const char *fmt, ...)
void **backtrace_addresses = malloc(sizeof(void*) * 32);
int backtrace_count = backtrace(backtrace_addresses, 32);
- char **backtrace_symbolnames = backtrace_symbols(backtrace_addresses, backtrace_count);
+ char **backtrace_symbolnames =
+ backtrace_symbols(backtrace_addresses, backtrace_count);
__asm__("_panic.spin_lock:");
__asm__("mov rax, 1");
@@ -141,16 +144,19 @@ void _panic(const char *fileorigin, const int lineorigin, const char *fmt, ...)
__asm__("jnz .spin_lock");
print(NOLOCK("5") "------------[ cut here ]------------");
- print(LOG_SOH "\7""0" "%s at %s:%d", mode_to_string[(int)mode], fileorigin, lineorigin);
+ print(LOG_SOH "\7""0" "%s at %s:%d", mode_to_string[(int)mode],
+ fileorigin, lineorigin);
vaprint(_fmt, ap);
print(LOG_SOH "\7""7" "Call Trace:");
for(int i = 0; i < backtrace_count; ++i) {
- print(NOLOCK("7") " [0x%016x] %s", backtrace_addresses[i], backtrace_symbolnames[i]);
+ print(NOLOCK("7") " [0x%016x] %s", backtrace_addresses[i],
+ backtrace_symbolnames[i]);
}
if(mainpid == pid){
print(NOLOCK("7") " <start of main thread>");
} else {
- print(NOLOCK("7") " <start of %s[%d]>", subsystem_get_name(pid), pid);
+ print(NOLOCK("7") " <start of %s[%d]>",
+ subsystem_get_name(pid), pid);
}
/* if we are going to die, we dont really need to clean up */
diff --git a/init/subsys.c b/init/subsys.c
index d080ba6..3db2cb5 100644
--- a/init/subsys.c
+++ b/init/subsys.c
@@ -41,7 +41,8 @@ static int __subsystem_entry(struct subsystem_info *info)
prctl(PR_SET_NAME, name);
free(name);
- print(LOG_DEBUG "subsys: starting subsystem %s (%d)", info->fn_name, getpid());
+ print(LOG_DEBUG "subsys: starting subsystem %s (%d)",
+ info->fn_name, getpid());
int ret = info->fn();
@@ -81,13 +82,16 @@ int subsystem_handle_term(int pid)
if(!subsystem || subsystem->pid != pid)
continue;
- print(LOG_DEBUG "subsys: subsystem terminated %s (%d)", subsystem->fn_name, pid);
+ print(LOG_DEBUG "subsys: subsystem terminated %s (%d)",
+ subsystem->fn_name, pid);
if(subsystem->mode == PANICMODE_RESPAWN
&& subsystem->respawn_count < MAX_RESPAWN) {
++(subsystem->respawn_count);
- int pid = clone((int (*)(void *))__subsystem_entry, (void *)((long)(subsystem->stack) + stack_size), CLONE_FILES | CLONE_VM | SIGCHLD, subsystem);
+ int pid = clone((int (*)(void *))__subsystem_entry,
+ (void *)((long)(subsystem->stack) + stack_size),
+ CLONE_FILES | CLONE_VM | SIGCHLD, subsystem);
subsystem->pid = pid;
if(pid < 0) {
print(LOG_CRIT "subsys: cannot re-start subsystem %s: "
diff --git a/net/api.c b/net/api.c
index e664c42..9da0e8e 100644
--- a/net/api.c
+++ b/net/api.c
@@ -26,7 +26,8 @@ int http_get(char *url)
curl_easy_setopt(job, CURLOPT_URL, url);
curl_easy_setopt(job, CURLOPT_WRITEDATA, write_end);
- curl_easy_setopt(job, CURLOPT_HTTPHEADER, curl_slist_append(NULL, token));
+ curl_easy_setopt(job, CURLOPT_HTTPHEADER,
+ curl_slist_append(NULL, token));
CURLcode res = curl_easy_perform(job);
if(res > 0) {
diff --git a/net/net.c b/net/net.c
index fada07c..da8680d 100644
--- a/net/net.c
+++ b/net/net.c
@@ -21,7 +21,8 @@ int net_subsystem(void)
void net_get_gateway_url()
{
- curl_version_info_data *curl_version = curl_version_info(CURLVERSION_NOW);
+ curl_version_info_data *curl_version =
+ curl_version_info(CURLVERSION_NOW);
const char * const* curl_protocols = curl_version->protocols;
int wss_supported = 0;
for(int i = 0; curl_protocols[i]; ++i) {
@@ -43,14 +44,18 @@ void net_get_gateway_url()
close(fd);
cJSON *gateway_info = cJSON_ParseWithLength(buf, buf_length);
- cJSON *gateway_url_json = cJSON_GetObjectItemCaseSensitive(gateway_info, "url");
- if(!cJSON_IsString(gateway_url_json) || gateway_url_json->valuestring == NULL) {
- print(LOG_ERR "net: cannot get gateway url from api (token invalid?)");
+ cJSON *gateway_url_json =
+ cJSON_GetObjectItemCaseSensitive(gateway_info, "url");
+ if(!cJSON_IsString(gateway_url_json) ||
+ gateway_url_json->valuestring == NULL) {
+ print(LOG_ERR "net: cannot get gateway url from api "
+ "(token invalid?)");
cJSON_Delete(gateway_info);
goto assume;
}
- char *gateway_url = calloc(strlen(gateway_url_json->valuestring) + 1, sizeof(char));
+ char *gateway_url = calloc(strlen(gateway_url_json->valuestring) + 1,
+ sizeof(char));
strcpy(gateway_url, gateway_url_json->valuestring);
print(LOG_DEBUG "net: using gateway url %s", gateway_url);
@@ -60,7 +65,8 @@ void net_get_gateway_url()
assume:
print(LOG_DEBUG "net: assuming gateway url wss://gateway.discord.gg");
- gateway_url = calloc(strlen("wss://gateway.discord.gg") + 1, sizeof(char));
+ gateway_url = calloc(strlen("wss://gateway.discord.gg") + 1,
+ sizeof(char));
strcpy(gateway_url, "wss://gateway.discord.gg");
return;
}