Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sfdisk return 1 with successfully stop sfdisk #1413

Closed
mzhan0170 opened this issue Aug 17, 2021 · 4 comments
Closed

sfdisk return 1 with successfully stop sfdisk #1413

mzhan0170 opened this issue Aug 17, 2021 · 4 comments

Comments

@mzhan0170
Copy link

Based on code, seems the return value of this command could be 1 for success case.
So, if scripts uses sfdisk command, and need check the result of success, need check 0 and 1 bothly.
That's maby not consistent with general-purpose of return value 1.

Could you help update the man page of sfdisk to let user notice this?
What's your opinion?

Thanks,
Mark

@karelzak
Copy link
Collaborator

It uses standard EXIT_ stdlib.h macros:

$ tail -3 disk-utils/sfdisk.c
	return rc == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}

$ grep EXIT_ /usr/include/stdlib.h 
#define	EXIT_FAILURE	1	/* Failing exit status.  */
#define	EXIT_SUCCESS	0	/* Successful exit status.  */

it means 0 for success.

Do you have an example when it returns 1 ?

@mzhan0170
Copy link
Author

We run the sfdisk like below scripts, in ksh:

a=$(print "\
	\nsfdisk ${device.name}<<-EOF\
	\n0,0,0
	\n0,0,0
	\n0,0,0
	\n0,0,0
	\nEOF")

eval ${a}
I always get 1 from the result: $?==1. I 'm not sure if this case match the case of: SFDISK_DONE_EOF

Thanks,
Mark

@karelzak
Copy link
Collaborator

The exit code works as expected.

The problem is that sfdisk does not write an empty disklabel by default (see man page). You have to specify "label: dos" to force it to write an empty label. Unfortunately, there is a bug and this feature does not work as expected when empty partitions are specified (fixed now).

For your use case, you need

echo -e "label: dos\n0,0,0\n0,0,0\n0,0,0\n"0,0,0\n |  sfdisk <device>

@karelzak
Copy link
Collaborator

Thanks for your report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants