last_patch64 from vodz:
The following usage from original user: $ ./busybox swapon -a Have typo problem: swapon: swapon: Operation not permitted But regular version: swapon: /dev/hda5: Operation not permitted Patch attached, reduced 9 bytes and advanced exit code also.
This commit is contained in:
parent
fda2b7ff47
commit
db1df5ebeb
@ -39,13 +39,13 @@ extern int swapoff (__const char *__path);
|
|||||||
|
|
||||||
#include "busybox.h"
|
#include "busybox.h"
|
||||||
|
|
||||||
static int whichApp;
|
static int whichApp; /* default SWAPON_APP */
|
||||||
|
|
||||||
static const int SWAPON_APP = 1;
|
static const int SWAPON_APP = 0;
|
||||||
static const int SWAPOFF_APP = 2;
|
static const int SWAPOFF_APP = 1;
|
||||||
|
|
||||||
|
|
||||||
static void swap_enable_disable(char *device)
|
static int swap_enable_disable(const char *device)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
@ -54,32 +54,35 @@ static void swap_enable_disable(char *device)
|
|||||||
else
|
else
|
||||||
status = swapoff(device);
|
status = swapoff(device);
|
||||||
|
|
||||||
if (status != 0)
|
if (status != 0) {
|
||||||
perror_msg_and_die(applet_name);
|
perror_msg("%s", device);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void do_em_all(void)
|
static int do_em_all(void)
|
||||||
{
|
{
|
||||||
struct mntent *m;
|
struct mntent *m;
|
||||||
FILE *f = setmntent("/etc/fstab", "r");
|
FILE *f = setmntent("/etc/fstab", "r");
|
||||||
|
int err = 0;
|
||||||
|
|
||||||
if (f == NULL)
|
if (f == NULL)
|
||||||
perror_msg_and_die("/etc/fstab");
|
perror_msg_and_die("/etc/fstab");
|
||||||
while ((m = getmntent(f)) != NULL) {
|
while ((m = getmntent(f)) != NULL) {
|
||||||
if (strcmp(m->mnt_type, MNTTYPE_SWAP)==0) {
|
if (strcmp(m->mnt_type, MNTTYPE_SWAP)==0) {
|
||||||
swap_enable_disable(m->mnt_fsname);
|
if(swap_enable_disable(m->mnt_fsname) == EXIT_FAILURE)
|
||||||
|
err++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
endmntent(f);
|
endmntent(f);
|
||||||
exit(EXIT_SUCCESS);
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
extern int swap_on_off_main(int argc, char **argv)
|
extern int swap_on_off_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
if (strcmp(applet_name, "swapon") == 0) {
|
if (applet_name[5] == 'f') { /* "swapoff" */
|
||||||
whichApp = SWAPON_APP;
|
|
||||||
} else {
|
|
||||||
whichApp = SWAPOFF_APP;
|
whichApp = SWAPOFF_APP;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,14 +103,13 @@ extern int swap_on_off_main(int argc, char **argv)
|
|||||||
if (stat("/etc/fstab", &statBuf) < 0)
|
if (stat("/etc/fstab", &statBuf) < 0)
|
||||||
error_msg_and_die("/etc/fstab file missing");
|
error_msg_and_die("/etc/fstab file missing");
|
||||||
}
|
}
|
||||||
do_em_all();
|
return do_em_all();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
goto usage_and_exit;
|
goto usage_and_exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
swap_enable_disable(*argv);
|
return swap_enable_disable(*argv);
|
||||||
return EXIT_SUCCESS;
|
|
||||||
|
|
||||||
usage_and_exit:
|
usage_and_exit:
|
||||||
show_usage();
|
show_usage();
|
||||||
|
Loading…
Reference in New Issue
Block a user