Commit graph

1072 commits

Author SHA1 Message Date
Ben Wiederhake
a2feef17bf Meta+Userland: Make clang-format-10 clean 2020-09-25 21:18:17 +02:00
Andreas Kling
ed5407a3d7 js: Use VM::exception() instead of Interpreter::exception()
The VM is always there, but we only have an Interpreter while we are
running code.
2020-09-23 21:30:18 +02:00
Andreas Kling
4a8bfcdd1c LibJS: Move the current exception from Interpreter to VM
This will allow us to throw exceptions even when there is no active
interpreter in the VM.
2020-09-22 20:10:20 +02:00
Peter Elliott
7ba7b72736 Userland: Convert passwd(1) to use Core::Account
this fixes the passwd issues discovered in #3296
2020-09-21 20:18:05 +02:00
Peter Elliott
4a834f969f Userland: Switch su over to Core::Account 2020-09-21 20:18:05 +02:00
Andreas Kling
df3ff76815 LibJS: Rename InterpreterScope => InterpreterExecutionScope
To make it a little clearer what this is for. (This is an RAII helper
class for adding and removing an Interpreter to a VM's list of the
currently active (executing code) Interpreters.)
2020-09-21 14:35:12 +02:00
Andreas Kling
b7ce0680dd test-web: Keep the Interpreter on the VM interpreter stack during test 2020-09-21 14:34:40 +02:00
Andreas Kling
1c43442be4 LibJS+Clients: Add JS::VM object, separate Heap from Interpreter
Taking a big step towards a world of multiple global object, this patch
adds a new JS::VM object that houses the JS::Heap.

This means that the Heap moves out of Interpreter, and the same Heap
can now be used by multiple Interpreters, and can also outlive them.

The VM keeps a stack of Interpreter pointers. We push/pop on this
stack when entering/exiting execution with a given Interpreter.
This allows us to make this change without disturbing too much of
the existing code.

There is still a 1-to-1 relationship between Interpreter and the
global object. This will change in the future.

Ultimately, the goal here is to make Interpreter a transient object
that only needs to exist while you execute some code. Getting there
will take a lot more work though. :^)

Note that in LibWeb, the global JS::VM is called main_thread_vm(),
to distinguish it from future worker VM's.
2020-09-20 19:24:44 +02:00
Nico Weber
8212ba467c ntpquery: Use SO_TIMESTAMP to get a more accurate destination_timestamp
We can now see at which time a packet was received by the network
adapter, instead of having to measure user time after receiving
the packet in user space.

This means the destination timestamp is no longer affected by in-kernel
queuing delays, which can be tens of milliseconds when the system
is under load.

It also means that if ntpquery grows a message queue that waits on
replies from several requests, the time used processing one response
won't be incorrectly included in the destination timestamp of the
next response (in case two responses arrive at the network adapter
at roughly the same time).

NTP's calculations work better if send and receive latency are
about equal, and this only removes in-kernel queue delays and
context switch delays for the receiving packet. But the two
latencies aren't very equal anyways because $network. Also, maybe
we can add another API for setting the send time in the outgoing
packet in kernel space right before (or when) hitting the network
adapter and use that here too. So this still seems like progress.
2020-09-17 17:23:01 +02:00
asynts
2229b13c97 Userland: Allow executing binaries from PATH with env.
This is useful for shebangs:

    #!/bin/env Shell
    echo "Hello, World!"
2020-09-16 19:39:17 +02:00
asynts
c577f6e139 Userland: Use find_executable_in_path in which. 2020-09-16 19:39:17 +02:00
asynts
96edcbc27c AK: Lower the requirements for InputStream::eof and rename it.
Consider the following snippet:

    void foo(InputStream& stream) {
        if(!stream.eof()) {
            u8 byte;
            stream >> byte;
        }
    }

There is a very subtle bug in this snippet, for some input streams eof()
might return false even if no more data can be read. In this case an
error flag would be set on the stream.

Until now I've always ensured that this is not the case, but this made
the implementation of eof() unnecessarily complicated.
InputFileStream::eof had to keep a ByteBuffer around just to make this
possible. That meant a ton of unnecessary copies just to get a reliable
eof().

In most cases it isn't actually necessary to have a reliable eof()
implementation.

In most other cases a reliable eof() is avaliable anyways because in
some cases like InputMemoryStream it is very easy to implement.
2020-09-14 20:58:12 +02:00
Linus Groh
e9562e1920 Userland: Add {md5,sha1,sha256,sha512}sum 2020-09-13 11:37:56 +02:00
AnotherTest
bc9f8f5c39 Userland: Add an implementation of printf 2020-09-11 21:41:23 +02:00
asynts
3c03ce0c80 LibCompress: Add unit tests for CanonicalCode. 2020-09-11 16:07:45 +02:00
asynts
4af8eea56f LibCompress: Return Optional from decompress_all method. 2020-09-11 16:07:45 +02:00
asynts
b0ba7a897f Userland: gunzip if filename doesn't end in .gz append it.
This is the behaviour of gzip on my Linux system.
2020-09-11 16:07:45 +02:00
Sergey Bugaev
039e529dbe Userland: Fix a signal race condition
It has been possible for a signal to arrive in between us checking
g_interrupted and exiting - sucessfully, even though we were interrupted.

This way, if a signal arrives before we reset the disposition, we
will reliably check for it later; if it arrives afterwards, it'll
kill us automatically.
2020-09-10 16:00:11 +02:00
Andreas Kling
606f83436d test-js: Catch SIGINFO and dump the current test name + pass/fail/skip
This is pretty handy if the JS tests take a long time to run and you
wonder what they're doing. :^)
2020-09-09 21:10:23 +02:00
Andreas Kling
687aad01be test-js: Add -g option to run a garbage collection on each allocation
This is very slow, but very good at flushing out GC bugs. :^)
2020-09-09 21:10:23 +02:00
Nico Weber
a2a54f459f sleep: Make variable written in signal handler volatile
No difference in practice, but it's tidier and protects us
if we ever use g_interrupted earlier in main -- in that case,
the compiler might chose to keep the variable in a register without
the volatile.

Found by @bugaevc, thanks!
2020-09-09 20:25:19 +02:00
Nico Weber
42153221a5 sleep: On SIGINT, call default SIGINT handler after printing remaining time
With this, hitting ctrl-c twice in `for i in $(seq 10) { sleep 1 }`
terminates the loop as expected (...well, I'd expect it to quit after
just one ctrl-c, but serenity's shell makes a single ctrl-c only
quit the current loop iteration).

Part of #3419.
2020-09-09 12:44:35 +02:00
asynts
9c83d6ff46 Refactor: Replace usages of FixedArray with Array. 2020-09-08 14:01:21 +02:00
Nico Weber
4ac5cc2461 ntpquery: Compute and print delay and offset 2020-09-07 11:22:48 +02:00
Nico Weber
f1a6884a51 ntpquery: Add a -s flag to make it adjust the time 2020-09-06 21:50:55 +02:00
Nico Weber
0736ae4116 ntpquery: Use time.google.com as default NTP server for now
Using a pool.ntp.org server seems nicer and more open-source-y,
but until our pool use is approved, let's put in a default value
that works.

(time.google.com serves smeared time instead of doing leap seconds.
pool.ntp.org doesn't serve smeared time. I intend to implement
client-side leap second smearing since nobody likes jumpy timestamps.
For now, we get this for free.)
2020-09-06 21:50:55 +02:00
Nico Weber
8016b2c546 ntpquery: Record destination timestamp as well 2020-09-06 21:50:55 +02:00
Andreas Kling
bc48181939 Userland: Add missing license headers to "w" and "utmpupdate" 2020-09-06 20:44:16 +02:00
Andreas Kling
4e2ccde85a Userland: Shorten "w" idle time format
Let's just say "123s" for now (instead of "123 sec")
2020-09-06 19:13:52 +02:00
Andreas Kling
6dc5cda50d Userland: Bring back improved "LOGIN@" column in "w"
This actually looks a lot nicer if we slim down the datetime format.
Also remove the "FROM" column which was the one I actually didn't want.
2020-09-06 19:13:00 +02:00
Andreas Kling
c995166c56 utmpupdate: Store the login time in /var/run/utmp as a Unix timestamp
This is obviously nicer and makes it easy for other programs to do what
they want with the timestamp.
2020-09-06 19:08:09 +02:00
Andreas Kling
d531b4fa61 Userland: Show the current foreground process name in "w" output
Add a "WHAT" column that shows which command is currently executing in
each active session. Very neat :^)
2020-09-06 19:05:08 +02:00
Andreas Kling
6d8c4af9c2 LibCore+top: Use pid_t for pgid/pgrp/sid numbers 2020-09-06 19:04:47 +02:00
Andreas Kling
5a934c37cf Userland: Remove "LOGIN@" column from "w" since it's not really useful
Maybe we can bring this back once we have remote logins, or at least
make it optional then. At the moment, it's not very interesting.
2020-09-06 18:59:56 +02:00
Andreas Kling
abce7e7ca2 Userland: Show idle times in "w" output
The idle time is based on the mtime of the session's TTY :^)
2020-09-06 18:58:58 +02:00
Andreas Kling
ae9c5bf216 Userland: Tweak "w" output just slightly 2020-09-06 18:48:00 +02:00
Andreas Kling
8e489b451a Userland: Add a simple 'w' program that shows current terminal sessions
This fetches information from /var/run/utmp and shows the interactive
sessions in a little list. More things can be added here to make it
more interesting. :^)
2020-09-06 16:16:10 +02:00
Andreas Kling
171bfcff36 utmpupdate: Use pledge() and unveil() 2020-09-06 16:14:27 +02:00
Andreas Kling
dcd47655d0 utmpupdate: Add a program for updating /var/run/utmp
To keep track of ongoing terminal sessions, we now have a sort-of
traditional /var/run/utmp file, like other Unix systems.
Unlike other Unix systems however, ours is of course JSON. :^)

The /bin/utmpupdate program is used to update the file, which is
not writable by regular user accounts. This helper program is
set-GID "utmp".
2020-09-06 16:10:27 +02:00
asynts
5d85be7ed4 LibCompress: Add another unit test.
I suspected an error in CircularDuplexStream::read(Bytes, size_t). This
does not appear to be the case, this test case is useful regardless.

The following script was used to generate the test:

    import gzip

    uncompressed = []
    for _ in range(0x100):
        uncompressed.append(1)
    for _ in range(0x7e00):
        uncompressed.append(0)
    for _ in range(0x100):
        uncompressed.append(1)

    compressed = gzip.compress(bytes(uncompressed))
    compressed = ", ".join(f"0x{byte:02x}" for byte in compressed)

    print(f"""\
    TEST_CASE(gzip_decompress_repeat_around_buffer)
    {{
        const u8 compressed[] = {{
            {compressed}
        }};

        u8 uncompressed[0x8011];
        Bytes{{ uncompressed, sizeof(uncompressed) }}.fill(0);
        uncompressed[0x8000] = 1;

        const auto decompressed = Compress::GzipDecompressor::decompress_all({{ compressed, sizeof(compressed) }});

        EXPECT(compare({{ uncompressed, sizeof(uncompressed) }}, decompressed.bytes()));
    }}
    """, end="")
2020-09-06 12:54:45 +02:00
asynts
612c1bc84d Userland: Use Buffered<T> in gunzip. 2020-09-06 12:54:45 +02:00
Andreas Kling
51146e3075 LibGUI: Make the Clipboard API deal in raw byte buffers a bit more
To open up for putting not just text/plain content on the clipboard,
let's make the GUI::Clipboard API a bit more raw-data-friendly. :^)
2020-09-05 16:16:01 +02:00
Ben Wiederhake
c8668e9b7c Meta: Fix wonky copyright headers in Tests 2020-09-05 14:19:38 +02:00
Avery
6fe37cb471 Userland/tt: Use a default value for the test to run
Addresses #3394 which was caused by dereferencing null `test_name`
when no arguments were given to /bin/tt. Additionally, arguments
other than the defined tests now print usage and exit to avoid
running the default test.
2020-09-03 10:08:15 +02:00
AnotherTest
7e72285049 Userland: Allow unquoted 'filename' values in 'pro' 2020-08-31 23:05:58 +02:00
AnotherTest
861ce62e14 Userland: Improve 'ContentDispositionParser' in 'pro'
This patch just applies a suggestion, making the code more readable.
2020-08-31 23:05:58 +02:00
asynts
1c8312fa50 LibCompress: Fix a bug when wrapping around the buffer. 2020-08-31 23:04:55 +02:00
AnotherTest
cb7526fca0 Userland: Make 'pro' capable of guessing a filename
The whole thing with `pro url > filename` was getting annoying, so let's
just have it support Content-Disposition and guessing from the URL.
2020-08-31 09:14:11 +02:00
Nico Weber
d1990281e1 ntpquery: Add routines for converting timeval<->ntp timestamps
Use them to set the transmit timestamp on the outgoing packet and
to print the returned timestamps as ISO 8601 strings.
2020-08-30 17:37:20 +02:00
Nico Weber
73db67e806 Userland: Add an extremely simple NTP client
This only queries a single NTP server, only does a point-to-point
request, doens't do any filtering, doesn't display the response
in any useful format, and is generally very bare-bones.

But maybe, over time it can learn to query more servers, do
filtering, run as a service that keeps state over time to
improve filtering, adjust system time, and maybe learn to
run as an NTP server then.
2020-08-30 17:37:20 +02:00