update: fix formatting

This commit is contained in:
ngn 2024-05-05 23:26:01 +03:00
parent 88b948e186
commit c8bdc795a9
3 changed files with 39 additions and 39 deletions

View File

@ -185,7 +185,7 @@ bool config_load(config_t *config, char *path) {
void config_print(config_t *config) {
info(_("Configuration details:\n"));
printf(COLOR_BOLD " %s " COLOR_RESET "=> %s\n", _("Name"), config->name);
if(NULL != config->desc)
if (NULL != config->desc)
printf(COLOR_BOLD " %s " COLOR_RESET "=> %s\n", _("Desc"), config->desc);
printf(COLOR_BOLD " %s " COLOR_RESET "=> %s\n", _("Author"), config->author);

View File

@ -4,9 +4,9 @@
#include "error.h"
#include "log.h"
#include "paths.h"
#include "run.h"
#include "url.h"
#include "util.h"
#include "run.h"
#include <git2.h>
#include <git2/global.h>
@ -110,7 +110,7 @@ COPY:
info(_("Copying all the targets"));
char **argv = NULL;
int argc = 0, indx = 0;
int argc = 0, indx = 0;
while (cur && ++counter > 0) {
target_print(cur);
@ -127,35 +127,35 @@ COPY:
}
argc += cur->require.s;
if(0 == argc)
if (0 == argc)
goto NEXT;
if(NULL == argv)
argv = malloc(sizeof(char*)*argc);
if (NULL == argv)
argv = malloc(sizeof(char *) * argc);
else
argv = realloc(argv, sizeof(char*)*argc);
argv = realloc(argv, sizeof(char *) * argc);
for(int i = 0; i < cur->require.s; i++){
for (int i = 0; i < cur->require.s; i++) {
argv[indx] = cur->require.c[i];
indx++;
}
NEXT:
NEXT:
cur = cur->next;
}
if(NULL == argv){
if (NULL == argv) {
ret = true;
goto END;
}
argc++;
argv = realloc(argv, sizeof(char*)*argc);
argv = realloc(argv, sizeof(char *) * argc);
argv[indx] = NULL;
ret = true;
ret = true;
info(_("Installing all the requirements"));
if(!run_cmd_root("mp-install", argv)){
if (!run_cmd_root("mp-install", argv)) {
ret = false;
error(_("Failed to run the mp-install command"));
details(errch);

View File

@ -1,33 +1,33 @@
#include <sys/wait.h>
#include <spawn.h>
#include <stdbool.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <spawn.h>
#include <stdio.h>
#include <sys/wait.h>
#include <unistd.h>
#include "error.h"
#include "util.h"
#include "run.h"
#include "util.h"
extern char **environ;
char *run_find_cmd(char *cmd){
char *run_find_cmd(char *cmd) {
char *path = getenv("PATH"), *save, *el;
while((el = strtok_r(path, ":", &save)) != NULL){
char fp[strlen(el)+strlen(cmd)+2];
while ((el = strtok_r(path, ":", &save)) != NULL) {
char fp[strlen(el) + strlen(cmd) + 2];
join(fp, el, cmd);
if(exists(fp))
if (exists(fp))
return strdup(fp);
}
return NULL;
}
bool run_cmd(char **all){
bool run_cmd(char **all) {
pid_t pid;
if(posix_spawn(&pid, all[0], NULL, NULL, all, environ) != 0)
if (posix_spawn(&pid, all[0], NULL, NULL, all, environ) != 0)
return false;
int status;
@ -35,20 +35,20 @@ bool run_cmd(char **all){
return status == 0;
}
bool run_cmd_root(char *cmd, char **args){
bool run_cmd_root(char *cmd, char **args) {
char *rootcmd = NULL;
if(NULL == run_find_cmd(cmd)){
if (NULL == run_find_cmd(cmd)) {
error_set("Command not found");
errno = RunCmdNotFound;
return false;
}
if(getuid()==0)
if (getuid() == 0)
goto RUN;
else if((rootcmd = run_find_cmd("doas")) != NULL)
else if ((rootcmd = run_find_cmd("doas")) != NULL)
goto RUN;
else if((rootcmd = run_find_cmd("sudo" )) != NULL)
else if ((rootcmd = run_find_cmd("sudo")) != NULL)
goto RUN;
error_set("There is no doas or sudo installed");
@ -57,32 +57,32 @@ bool run_cmd_root(char *cmd, char **args){
RUN:
int arg_count = 0;
while(args[arg_count] != NULL)
while (args[arg_count] != NULL)
arg_count++;
arg_count += 2;
if(rootcmd != NULL)
if (rootcmd != NULL)
arg_count++;
char **all = malloc(arg_count*sizeof(char*));
int indx = 0;
char **all = malloc(arg_count * sizeof(char *));
int indx = 0;
if(rootcmd != NULL){
all[indx] = rootcmd;
if (rootcmd != NULL) {
all[indx] = rootcmd;
all[++indx] = cmd;
}else
} else
all[indx] = rootcmd;
for(int i = 0; i < arg_count; i++)
for (int i = 0; i < arg_count; i++)
all[++indx] = args[i];
all[++indx] = NULL;
bool ret = true;
if(!run_cmd(all)){
if (!run_cmd(all)) {
error_set("Command failed");
errno = RunCmdFail;
ret = false;
ret = false;
}
free(all);