You are not logged in.

#1 2013-12-30 02:59:13

wesleyac
Member
Registered: 2013-08-27
Posts: 80

How to start a replacement to agetty on boot?

Hello!

I'm working on a little Login/Display manager, and want it to start in place of agetty.  I am however, very new to the boot process, so I need some help.

My idea is to use the ExecStart option to agetty as described here.  When I tried:

[Service]
ExecStart=
ExecStart=/usr/bin/echo hello

as /etc/systemd/system/getty@tty3.service.d/autologin.conf, tty3 just shows a blinking cursor.

I also think that I would have to use the login command to log in the user, but as you can see, I haven't gotten that far yet tongue  Is that correct?

My other idea was to make a service that would replace agetty and enable it, but I have no idea how to go about that.

How can I get a program to start in the place of agetty?

Thanks,

Wesley.

Offline

#2 2013-12-30 03:13:12

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,548
Website

Re: How to start a replacement to agetty on boot?

wesleyac wrote:

tty3 just shows a blinking cursor.

That's because nothing is running on tty3.  Nothing in your echo command initializes tty3.  This is what agetty does, and this is why the %I is in the original service file so the agetty program knows which tty it should initialize.

edit: you might be able to "echo some-text-here > /dev/tty3" to get that text to show up, but I highly doubt you'd be satisfied with the result.

Last edited by Trilby (2013-12-30 03:17:34)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2013-12-30 03:14:48

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: How to start a replacement to agetty on boot?

'echo' is not a shell, you need a shell to run 'echo' in.

What exactly are you trying to do, why isn't agetty good enough for you? Do you want to print a custom welcome message or ...?

Offline

#4 2013-12-30 03:20:21

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,548
Website

Re: How to start a replacement to agetty on boot?

Karol, that's not strictly true.  Echo will execute as expected - but the stdout simply isnt connected where the OP wants it to be.  Nothing about 'echo' tells it *where* to echo.  This is one of agetty's jobs: to connect the standard streams to the desired tty.

EDIT: but my previous post wasn't entirely correct either.  You couldn't "echo hello > /dev/tty3" as the ">" redirection operator *is* a shell function - and with no shell, you cannot redirect output like that.  Perhaps you could have `/usr/bin/bash -c "echo hello >/dev/tty3"` but then what's the point.

Last edited by Trilby (2013-12-30 03:24:05)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#5 2013-12-30 04:24:34

wesleyac
Member
Registered: 2013-08-27
Posts: 80

Re: How to start a replacement to agetty on boot?

Trilby wrote:
wesleyac wrote:

tty3 just shows a blinking cursor.

That's because nothing is running on tty3.  Nothing in your echo command initializes tty3.  This is what agetty does, and this is why the %I is in the original service file so the agetty program knows which tty it should initialize.

Ah, I see.  I guess I'll look in the getty docs then, or maybe at the source for qingy.

karol wrote:

What exactly are you trying to do, why isn't agetty good enough for you? Do you want to print a custom welcome message or ...?

If I wanted a custom welcome message I'd use /etc/issue.  I'm making a framebuffer login and display manager.  I already have most of the barebones gui coded, I just need to figure out how to make it work without having to login via getty.

Trilby wrote:

Perhaps you could have `/usr/bin/bash -c "echo hello >/dev/tty3"` but then what's the point.

I don't see what's pointless about that.  If I understand correctly, it will run echo on tty3, thus acheving what I want.  Is that incorrect?  Or does bash start as a login shell if I call it like that?  As I said, I don't understand much of the boot process.

EDIT:
If I pipe my current program into /dev/tty3, stdout displays there, but the framebuffer displays on tty7 (I always run X on tty1).  I'm tring to figure out how to get the framebuffer to display on ttyX, but no luck so far.
Edit to my edit: That might actually be a side effect of running as root hmm

Last edited by wesleyac (2013-12-30 07:12:03)

Offline

#6 2013-12-30 07:40:17

wesleyac
Member
Registered: 2013-08-27
Posts: 80

Re: How to start a replacement to agetty on boot?

I'm writing this as a new post because it covers a very different topic.

I was looking at the source of mingetty, and I think that if I call the function open_tty() (line 134, mingetty.c), then execute another program that it will work.  am I correct?  I am not very good at C, but I think that that's what it should do.

Offline

#7 2013-12-30 12:42:46

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,548
Website

Re: How to start a replacement to agetty on boot?

Well this is a barrel full of x-y problems.  First, I think running bash the way I indicated would be pointless, as why bother doing that at all?  Just put something in bashrc to run on that tty and leave agetty in place - perhaps with auto-login set up.

Connecting the standard streams is fairly easy - they just need to be (re)opened to /dev/ttyX.

Setting up a framebuffer, however, is something different.

If you want to know if your idea will work - try it.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#8 2013-12-30 19:33:18

wesleyac
Member
Registered: 2013-08-27
Posts: 80

Re: How to start a replacement to agetty on boot?

Trilby wrote:

Just put something in bashrc to run on that tty and leave agetty in place - perhaps with auto-login set up.

I would do that, but then if someone crashes the dm, they are logged in, whereas if I replace agetty, they would just be at a blank screen.

Trilby wrote:

Setting up a framebuffer, however, is something different.

Do you have a link to something that explains how framebuffers work?  I've just been copy pasting code so far. tongue

Thanks,

Wesley

Offline

#9 2013-12-31 23:17:17

wesleyac
Member
Registered: 2013-08-27
Posts: 80

Re: How to start a replacement to agetty on boot?

Ok, so I've been working more on this, and I think I have it close to figured out.

My plan is to run the framebuffer on tty7 (The default, for some reason) and once the person logs in, run bash on tty7.  I, however need to figure out how to get bash to run on a specific tty.

What I have is this (I have access to all shell function btw):

pkill agetty
/usr/bin/bash > /dev/ttyX

However, that doesn't work as expected.

Last edited by wesleyac (2013-12-31 23:42:28)

Offline

#10 2014-01-01 00:25:26

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,548
Website

Re: How to start a replacement to agetty on boot?

No, because that just sends the output to ttyX.  You need to connect input output and error streams.

But why are you going to run bash on a tty where you're running a framebuffer to (presumably) have some graphical login - again this is just one X-Y problem after another: what do you really want to do?

If you are going to run bash on a tty, why are you trying to replace agetty?

What language are you using?  If it's C, then (assuming you really want to run bash on tty7) then all you should need to do is freopen() stdin, stdout, and stderr to /dev/tty7, then execv().  But I'm not sure what this would accomplish then.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

Board footer

Powered by FluxBB