Skip to content

Commit

Permalink
Use chmod_chown() API from utils
Browse files Browse the repository at this point in the history
 * add bmips to OpenWrt CI build

Signed-off-by: Toni Uhlig <[email protected]>
  • Loading branch information
utoni committed Nov 14, 2024
1 parent 9105b39 commit b0e0e42
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 41 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build-openwrt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ jobs:
fail-fast: false
matrix:
include:
- arch: bcm63268
target: bmips-bcm63268

- arch: arm_cortex-a9_vfpv3-d16
target: mvebu-cortexa9

Expand Down
62 changes: 21 additions & 41 deletions examples/c-analysed/c-analysed.c
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,11 @@ static int parse_options(int argc, char ** argv)
if (access(csv_outfile, F_OK) != 0 && errno == ENOENT)
{
opt = 1;
} else {
if (chmod_chown(csv_outfile, S_IRUSR | S_IWUSR, "root", "root") != 0)
{
// skip "unused result" warning
}
}

csv_fp = fopen(csv_outfile, "a+");
Expand Down Expand Up @@ -1473,6 +1478,11 @@ static int parse_options(int argc, char ** argv)
if (access(stats_csv_outfile, F_OK) != 0 && errno == ENOENT)
{
opt = 1;
} else {
if (chmod_chown(stats_csv_outfile, S_IRUSR | S_IWUSR, "root", "root") != 0)
{
// skip "unused result" warning
}
}

stats_csv_fp = fopen(stats_csv_outfile, "a+");
Expand Down Expand Up @@ -2026,48 +2036,18 @@ int main(int argc, char ** argv)
goto failure;
}

if (user != NULL)
int ret;
ret = chmod_chown(csv_outfile, S_IRUSR | S_IWUSR | S_IRGRP, user, group);
if (ret != 0)
{
struct passwd * pwd;
struct group * grp;
gid_t gid;

errno = 0;
pwd = getpwnam(user);
if (pwd == NULL)
{
logger_early(1, "Get user failed: %s", strerror(errno));
goto failure;
}

if (group != NULL)
{
errno = 0;
grp = getgrnam(group);
if (grp == NULL)
{
logger_early(1, "Get group failed: %s", strerror(errno));
goto failure;
}
gid = grp->gr_gid;
}
else
{
gid = pwd->pw_gid;
}

if (csv_outfile != NULL &&
(chmod(csv_outfile, S_IRUSR | S_IWUSR) != 0 || chown(csv_outfile, pwd->pw_uid, gid) != 0))
{
logger_early(1, "Change user/group of `%s' failed: %s", csv_outfile, strerror(errno));
goto failure;
}
if (stats_csv_outfile != NULL &&
(chmod(stats_csv_outfile, S_IRUSR | S_IWUSR) != 0 || chown(stats_csv_outfile, pwd->pw_uid, gid) != 0))
{
logger_early(1, "Change user/group of `%s' failed: %s", stats_csv_outfile, strerror(errno));
goto failure;
}
logger_early(1, "Could not chmod/chown `%s': %s", csv_outfile, strerror(ret));
return 1;
}
ret = chmod_chown(stats_csv_outfile, S_IRUSR | S_IWUSR | S_IRGRP, user, group);
if (ret != 0)
{
logger_early(1, "Could not chmod/chown `%s': %s", stats_csv_outfile, strerror(ret));
return 1;
}

errno = 0;
Expand Down

0 comments on commit b0e0e42

Please sign in to comment.