Shell Received Segmentation Fault after writing a Shell Script - FreeBSD13 Stable

Clippers

New Member

Reaction score: 1
Messages: 12

I was following an example found in: Practical rc.d scripting in BSD - at https://docs.freebsd.org/en/articles/rc-scripting/ ...and the 1st example, shows the "dummy" script. So, I reproduced the script in /etc/rc.conf.d, then I corrected errors, set the execute bit, and made a run. # start dummy failed with not a command. Then, I found a SirDice comment mentioning the full path. So, I tried: # /bin/sh /etc/rc.conf.d/dummy start - now it ran correctly, displaying a simple output message: Nothing Done. Afterwards, I was copying a file or two, nothing else, and I decided to run dummy again. # /bin/sh /etc/rc.conf.d/dummy start - but, after waiting for 30 seconds, came this response: Segmentation fault (core dumped). So, I rebooted but receive the same result. I have another basic shell program called myback and, when started, I receive the same segmentation fault message. I don’t really know how to identify the cause, I can't find (or understand) the .core dump file. I understand that the .core dump is Core Dump/Segmentation fault is a specific kind of error caused by accessing memory that “does not belong to you.” I have lately been experimenting with running transmission from the command line and also in KDE5. I receive a notification that terminal failed to acquire buffer space, but even then, the program did not crash or produce a segmentation error. I ran pkg delete transmission, but I still see the system attempting to redirect ports, so I know it's not completely gone. Any suggestions? PS this is a test system and I don't mind reloading F-BSD13 from scratch. Does anyone know more about getting a Segmentation fault after creating a few shell scripts?
 

Alain De Vos

Son of Beastie

Reaction score: 991
Messages: 3,066

Just paste your current scripts, we'll have a look.
PS: Crashing shell scripts are totally harmless. It's sometimes enough to put one bad character at a wrong place.
 

mark_j

Daemon

Reaction score: 870
Messages: 1,449

I'll start from the end. "Any suggestions?"
Yes.
Please use paragraphs. Your question is almost unintelligible.

Your best bet is to run script /tmp/log_my_crashes.txt
Then run your dummy script
Then type exit
Then post the result.
 

covacat

Daemon

Reaction score: 788
Messages: 1,446

you are supposed to put it in /etc/rc.d/
not /etc/rc.conf.d/
i think your setup creates infinite recursion
 

Alain De Vos

Son of Beastie

Reaction score: 991
Messages: 3,066

it's even better to put user scripts in /usr/local/etc/rc.d , that belonges to the packages & not to base.
 
OP
Clippers

Clippers

New Member

Reaction score: 1
Messages: 12

it's even better to put user scripts in /usr/local/etc/rc.d , that belonges to the packages & not to base.
I decided to go with the "even better" input. It seems to work. The problem is solved. My hat's off to you, Sir. TY.
 
OP
Clippers

Clippers

New Member

Reaction score: 1
Messages: 12

I'll start from the end. "Any suggestions?"
Yes.
Please use paragraphs. Your question is almost unintelligible.

Your best bet is to run script /tmp/log_my_crashes.txt
Then run your dummy script
Then type exit
Then post the result.
I solved the problem by relocating the script. But, here is the info you suggested might help.
Script started on Mon Nov 29 04:53:31 2021
You have mail.
root@godzilla:/tmp # # ^H[Kcd /etc/rc.conf.d
#: Command not found.
root@godzilla:/tmp # cd /etc
root@godzilla:/etc # cd rc.conf.d
root@godzilla:/etc/rc.conf.d # /bin/sh /etc/rc.conf.d/dummy start
Segmentation fault (core dumped)
root@godzilla:/etc/rc.conf.d #
root@godzilla:/etc/rc.conf.d # exit
exit
Script done on Mon Nov 29 04:59:03 2021
* No dinosaurs were hurt during this crash.
 

covacat

Daemon

Reaction score: 788
Messages: 1,446

load_rc_config will resource your script again and again and will finally bomb somehow
 
OP
Clippers

Clippers

New Member

Reaction score: 1
Messages: 12

Follow Up:
I found the core dump file: sh.core located in /etc/rc.conf.d The file is 1.3G
 

mark_j

Daemon

Reaction score: 870
Messages: 1,449

Yes, looking at rc.subr, it will recurse /etc/rc.conf.d (or /usr/local/etc/rc.conf.d) until either the stack gets exhausted or some other limit for the user's shell gets blasted.

Heads up to OP: follow the manual. Especially heed this old adage of woodworking: Measure twice, cut once. A simple mistake in putting it in the wrong directory crashed your shell. Bravo! 👏 :)

You can throw the core away, it's useless. Just put the script in the correct place and you'll get the result you want. Oh, and remove it when you no longer are testing/experimenting.
 
Top