---
name: "sd_journal_open_container"
section: "3"
platform: "linux"
package: "libsystemd-dev"
version: "215-17+deb8u7"
release: "Debian 8 (Jessie)"
platforms: ["linux"]
url: "https://new.carta.tech/sd_journal_open"
---

# sd\_journal\_open\_container(3)

Open the system journal for reading

Part of [sd\_journal\_open(3)](/sd_journal_open/3.md).

## NAME

sd\_journal\_open, sd\_journal\_open\_directory, sd\_journal\_open\_files, sd\_journal\_open\_container, sd\_journal\_close, sd\_journal, SD\_JOURNAL\_LOCAL\_ONLY, SD\_JOURNAL\_RUNTIME\_ONLY, SD\_JOURNAL\_SYSTEM, SD\_JOURNAL\_CURRENT\_USER - Open the system journal for reading

## SYNOPSIS

```
#include <systemd/sd-journal.h>
```

**int sd\_journal\_open(sd\_journal \*\****ret***, int** *flags***);**

**int sd\_journal\_open\_directory(sd\_journal \*\****ret***, const char \****path***, int** *flags***);**

**int sd\_journal\_open\_files(sd\_journal \*\****ret***, const char \*\****paths***, int** *flags***);**

**int sd\_journal\_open\_container(sd\_journal \*\****ret***, const char \****machine***, int** *flags***);**

**void sd\_journal\_close(sd\_journal \****j***);**

## DESCRIPTION

**sd\_journal\_open()** opens the log journal for reading. It will find all journal files automatically and interleave them automatically when reading. As first argument it takes a pointer to a *sd\_journal* pointer, which on success will contain a journal context object. The second argument is a flags field, which may consist of the following flags ORed together: **SD\_JOURNAL\_LOCAL\_ONLY** makes sure only journal files generated on the local machine will be opened. **SD\_JOURNAL\_RUNTIME\_ONLY** makes sure only volatile journal files will be opened, excluding those which are stored on persistent storage. **SD\_JOURNAL\_SYSTEM** will cause journal files of system services and the kernel (in opposition to user session processes) to be opened. **SD\_JOURNAL\_CURRENT\_USER** will cause journal files of the current user to be opened. If neither **SD\_JOURNAL\_SYSTEM** nor **SD\_JOURNAL\_CURRENT\_USER** are specified, all journal file types will be opened.

**sd\_journal\_open\_directory()** is similar to **sd\_journal\_open()** but takes an absolute directory path as argument. All journal files in this directory will be opened and interleaved automatically. This call also takes a flags argument, but it must be passed as 0 as no flags are currently understood for this call.

**sd\_journal\_open\_files()** is similar to **sd\_journal\_open()** but takes a **NULL**-terminated list of file paths to open. All files will be opened and interleaved automatically. This call also takes a flags argument, but it must be passed as 0 as no flags are currently understood for this call. Please note that in the case of a live journal, this function is only useful for debugging, because individual journal files can be rotated at any moment, and the opening of specific files is inherently racy.

**sd\_journal\_open\_container()** is similar to **sd\_journal\_open()** but opens the journal files of a running OS container. The specified machine name refers to a container that is registered with [**systemd-machined**(8)](/systemd-machined/8.md).

*sd\_journal* objects cannot be used in the child after a fork. Functions which take a journal object as an argument (**sd\_journal\_next()** and others) will return **-ECHILD** after a fork.

**sd\_journal\_close()** will close the journal context allocated with **sd\_journal\_open()** or **sd\_journal\_open\_directory()** and free its resources.

When opening the journal only journal files accessible to the calling user will be opened. If journal files are not accessible to the caller, this will be silently ignored.

See [**sd\_journal\_next**(3)](/sd_journal_next/3.md) for an example of how to iterate through the journal after opening it with **sd\_journal\_open()**.

A journal context object returned by **sd\_journal\_open()** references a specific journal entry as *current* entry, similar to a file seek index in a classic file system file, but without absolute positions. It may be altered with [**sd\_journal\_next**(3)](/sd_journal_next/3.md) and [**sd\_journal\_seek\_head**(3)](/sd_journal_seek_head/3.md) and related calls. The current entry position may be exported in *cursor* strings, as accessible via [**sd\_journal\_get\_cursor**(3)](/sd_journal_get_cursor/3.md). Cursor strings may be used to globally identify a specific journal entry in a stable way and then later to seek to it (or if the specific entry is not available locally, to its closest entry in time) [**sd\_journal\_seek\_cursor**(3)](/sd_journal_seek_cursor/3.md).

Notification of journal changes is available via **sd\_journal\_get\_fd()** and related calls.

## RETURN VALUE

The **sd\_journal\_open()**, **sd\_journal\_open\_directory()**, and **sd\_journal\_open\_files()** calls return 0 on success or a negative errno-style error code. **sd\_journal\_close()** returns nothing.

## NOTES

The **sd\_journal\_open()**, **sd\_journal\_open\_directory()** and **sd\_journal\_close()** interfaces are available as a shared library, which can be compiled and linked to with the **libsystemd** [**pkg-config**(1)](/pkg-config/1.md) file.

## HISTORY

**sd\_journal\_open()**, **sd\_journal\_close()**, **SD\_JOURNAL\_LOCAL\_ONLY**, **SD\_JOURNAL\_RUNTIME\_ONLY**, **SD\_JOURNAL\_SYSTEM\_ONLY** were added in systemd-38.

**sd\_journal\_open\_directory()** was added in systemd-187.

**SD\_JOURNAL\_SYSTEM**, **SD\_JOURNAL\_CURRENT\_USER**, and **sd\_journal\_open\_files()** were added in systemd-205. **SD\_JOURNAL\_SYSTEM\_ONLY** was deprecated.

## SEE ALSO

[**systemd**(1)](/systemd/1.md), [**sd-journal**(3)](/sd-journal/3.md), [**sd\_journal\_next**(3)](/sd_journal_next/3.md), [**sd\_journal\_get\_data**(3)](/sd_journal_get_data/3.md), [**systemd-machined**(8)](/systemd-machined/8.md)
